package conditions import ( "errors" "fmt" "testing" ) // **A test may take the store away while the keeper is still telling.** The keeper keeps every // transition from a goroutine of its own, so the memory store's failure is read there while a test // switches it: it is switched under the store's lock, or the race detector fails the suite at random // (it once failed TestAnUnreadableStoreClearsNothing). A hundred transitions still being kept while // the failure is switched a hundred times makes the race certain, not rare, when the lock is skipped. func TestTheStoreIsTakenAwayWhileTheKeeperIsTelling(t *testing.T) { k, store, told, _ := keeper(t) ctx := t.Context() const n = 100 for i := range n { if _, err := k.Observe(ctx, silent(fmt.Sprintf("m%d", i))); err != nil { t.Fatal(err) } } for range n { store.SetFail(errors.New("the bus is away")) store.SetFail(nil) } told.SetFail(errors.New("no responders")) told.SetFail(nil) settled(t, told, n) }