diff --git a/node-tools/internal/bus/state_pernode_test.go b/node-tools/internal/bus/state_pernode_test.go index 82baf52..ce6af1a 100644 --- a/node-tools/internal/bus/state_pernode_test.go +++ b/node-tools/internal/bus/state_pernode_test.go @@ -69,6 +69,7 @@ func TestAPerNodeStateIsServedAcrossEveryNodesBucket(t *testing.T) { var mu sync.Mutex var current, live []string + heard := make(chan struct{}, 1) stop, err := conn.StateWatch("mesh-provisioner", "mesh-host.composed", "", func(ch bus.StateChange) error { mu.Lock() defer mu.Unlock() @@ -77,6 +78,10 @@ func TestAPerNodeStateIsServedAcrossEveryNodesBucket(t *testing.T) { } else { live = append(live, ch.Key) } + select { + case heard <- struct{}{}: + default: + } return nil }) if err != nil { @@ -98,7 +103,10 @@ func TestAPerNodeStateIsServedAcrossEveryNodesBucket(t *testing.T) { if _, err := a.Put("a.m1.f5", []byte(`{"v":1}`)); err != nil { t.Fatal(err) } - mt.Until(t, func() error { + // Waited for as the watch hands each change over, not polled within a fixed five seconds: the new bucket is taken + // in on the bus's creation advisory, which a loaded machine delivers later (design 47 H, H-A-363). The bound only + // ends a watch that never hears it. + missing := func() error { mu.Lock() defer mu.Unlock() got := strings.Join(append(append([]string(nil), current...), live...), ",") @@ -108,5 +116,13 @@ func TestAPerNodeStateIsServedAcrossEveryNodesBucket(t *testing.T) { } } return nil - }) + } + bound := time.After(30 * time.Second) + for err := missing(); err != nil; err = missing() { + select { + case <-heard: + case <-bound: + t.Fatal(err) + } + } }