m/pkg/supervisor: move internal testhelpers

These are helper functions used for internal supervisor tests. This move
is in preparation for writing the other kind of 'test helers': ones that
are used by tests in other libraries when interacting with supervisor
types.

Change-Id: I64efe19b68c7c244ad426167565b0083a1b86fcf
Reviewed-on: https://review.monogon.dev/c/monogon/+/204
Reviewed-by: Leopold Schabel <leo@nexantic.com>
diff --git a/metropolis/pkg/supervisor/supervisor_test.go b/metropolis/pkg/supervisor/supervisor_test.go
index db84163..cf303e8 100644
--- a/metropolis/pkg/supervisor/supervisor_test.go
+++ b/metropolis/pkg/supervisor/supervisor_test.go
@@ -23,6 +23,34 @@
 	"time"
 )
 
+// waitSettle waits until the supervisor reaches a 'settled' state - ie., one
+// where no actions have been performed for a number of GC cycles.
+// This is used in tests only.
+func (s *supervisor) waitSettle(ctx context.Context) error {
+	waiter := make(chan struct{})
+	s.pReq <- &processorRequest{
+		waitSettled: &processorRequestWaitSettled{
+			waiter: waiter,
+		},
+	}
+
+	select {
+	case <-ctx.Done():
+		return ctx.Err()
+	case <-waiter:
+		return nil
+	}
+}
+
+// waitSettleError wraps waitSettle to fail a test if an error occurs, eg. the
+// context is canceled.
+func (s *supervisor) waitSettleError(ctx context.Context, t *testing.T) {
+	err := s.waitSettle(ctx)
+	if err != nil {
+		t.Fatalf("waitSettle: %v", err)
+	}
+}
+
 func runnableBecomesHealthy(healthy, done chan struct{}) Runnable {
 	return func(ctx context.Context) error {
 		Signal(ctx, SignalHealthy)