m/n/c/consensus: fix flaky TestEtcdMetrics
The metrics endpoint comes up before the bootstrap process is complete.
The test context then gets cancelled as the test has succeeded,
but the consensus runnable is not done bootstrapping, causing it to
return an error and TestHarness to
fail the test.
Fix this by waiting for the etcd state to be populated, indicating that
the bootstrap machinery has done its job.
Fixes https://github.com/monogon-dev/monogon/issues/258
Change-Id: Ied270191aaebb226822a1c9d7f8c6312bd0da1ed
Reviewed-on: https://review.monogon.dev/c/monogon/+/2043
Tested-by: Jenkins CI
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
diff --git a/metropolis/node/core/consensus/consensus_test.go b/metropolis/node/core/consensus/consensus_test.go
index 06d5d1b..f2bafba 100644
--- a/metropolis/node/core/consensus/consensus_test.go
+++ b/metropolis/node/core/consensus/consensus_test.go
@@ -94,6 +94,17 @@
ctxC, _ := supervisor.TestHarness(t, etcd.Run)
defer ctxC()
+ w := etcd.Watch()
+ // Wait until etcd state is populated as the metrics endpoint comes up
+ // before the bootstrap process is complete. The test context then gets
+ // cancelled as the test has succeeded, but the consensus runnable is not
+ // done bootstrapping, causing it to return an error and TestHarness to fail
+ // the test.
+ _, err := w.Get(b.ctx)
+ if err != nil {
+ t.Fatalf("status get failed: %v", err)
+ }
+
ctx, ctxC := context.WithCancel(context.Background())
defer ctxC()