m/pkg/value/etcd: fix test flakes on partitioning
Fixes monogon-dev/monogon#124
Change-Id: Ib1224dc809901d8dea61a297c3d836bd35f160c5
Reviewed-on: https://review.monogon.dev/c/monogon/+/689
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/metropolis/pkg/event/etcd/etcd_test.go b/metropolis/pkg/event/etcd/etcd_test.go
index f95fa0b..2f5e283 100644
--- a/metropolis/pkg/event/etcd/etcd_test.go
+++ b/metropolis/pkg/event/etcd/etcd_test.go
@@ -363,6 +363,16 @@
// operations will now hang.
tc.setEndpoints(0)
cluster.Members[0].InjectPartition(t, cluster.Members[1], cluster.Members[2])
+ // Let raft timeouts expire so that the leader is aware a partition has occurred
+ // and stops serving data if it is not part of a quorum anymore.
+ //
+ // Otherwise, if Member[0] was the leader, there will be a window of opportunity
+ // during which it will continue to serve read data even though it has been
+ // partitioned off. This is an effect of how etcd handles linearizable reads:
+ // they go through the leader, but do not go through raft.
+ //
+ // The value is the default etcd leader timeout (1s) + some wiggle room.
+ time.Sleep(time.Second + time.Millisecond*100)
// Perform the initial Get(), which should attempt to retrieve a KV entry from
// the etcd service. This should hang. Unfortunately, there's no easy way to do