metropolis/*: move tests to supervisor harness
This somewhat simplifies test code (barely), but more importantly pipes
logs from runnables into test stdout, thereby making debugging much
easier.
Change-Id: I3e597bbac8497bea3477afd54f61b592a0d08355
Reviewed-on: https://review.monogon.dev/c/monogon/+/206
Reviewed-by: Leopold Schabel <leo@nexantic.com>
diff --git a/metropolis/node/core/consensus/consensus_test.go b/metropolis/node/core/consensus/consensus_test.go
index 2671432..77ea63b 100644
--- a/metropolis/node/core/consensus/consensus_test.go
+++ b/metropolis/node/core/consensus/consensus_test.go
@@ -93,7 +93,7 @@
externalHost: "127.0.0.1",
})
- supervisor.New(b.ctx, etcd.Run)
+ supervisor.TestHarness(t, etcd.Run)
waitEtcd(t, etcd)
kv := etcd.Client()
@@ -116,7 +116,7 @@
Port: freeport.MustConsume(freeport.AllocateTCPPort()),
externalHost: "127.0.0.1",
})
- supervisor.New(b.ctx, etcd.Run)
+ supervisor.TestHarness(t, etcd.Run)
waitEtcd(t, etcd)
id, name, err := etcd.MemberInfo(b.ctx)
@@ -159,9 +159,9 @@
Port: freeport.MustConsume(freeport.AllocateTCPPort()),
externalHost: "127.0.0.1",
})
- ctx, ctxC := context.WithCancel(b.ctx)
- supervisor.New(ctx, etcd.Run)
+ ctxC, _ := supervisor.TestHarness(t, etcd.Run)
waitEtcd(t, etcd)
+
kv := etcd.Client()
if new {
if _, err := kv.Put(b.ctx, "/foo", "bar"); err != nil {
@@ -203,7 +203,7 @@
Port: freeport.MustConsume(freeport.AllocateTCPPort()),
externalHost: "127.0.0.1",
})
- supervisor.New(b.ctx, etcd.Run)
+ supervisor.TestHarness(t, etcd.Run)
waitEtcd(t, etcd)
etcd.stateMu.Lock()
diff --git a/metropolis/node/core/curator/curator_test.go b/metropolis/node/core/curator/curator_test.go
index 6ce489d..14c705a 100644
--- a/metropolis/node/core/curator/curator_test.go
+++ b/metropolis/node/core/curator/curator_test.go
@@ -221,7 +221,7 @@
// Start a new supervisor in which we create all curator DUTs.
dutC := make(chan *dut)
- supervisor.New(ctx, func(ctx context.Context) error {
+ supervisor.TestHarness(t, func(ctx context.Context) error {
for e, _ := range endpointToNum {
dutC <- newDut(ctx, t, e)
}
diff --git a/metropolis/node/core/curator/listener_test.go b/metropolis/node/core/curator/listener_test.go
index 0739d84..7e998da 100644
--- a/metropolis/node/core/curator/listener_test.go
+++ b/metropolis/node/core/curator/listener_test.go
@@ -54,15 +54,17 @@
}
// Start listener under supervisor.
- ctx, ctxC := context.WithCancel(context.Background())
- defer ctxC()
- supervisor.New(ctx, l.run)
+ supervisor.TestHarness(t, l.run)
// Begin with a follower.
val.Set(electionStatus{
follower: &electionStatusFollower{},
})
+ // Context for this test.
+ ctx, ctxC := context.WithCancel(context.Background())
+ defer ctxC()
+
// Simulate a request context.
ctxR, ctxRC := context.WithCancel(ctx)