From 9fddb35ef6fb59ee0609e981b354084c02df3e6f Mon Sep 17 00:00:00 2001 From: Steven van der Vegt Date: Wed, 9 Sep 2026 11:55:56 +0200 Subject: [PATCH] test(network): fix race in TestNotifier_VariousFlows/Happy_flow The subtest waited until the receiver callback had run twice and then read the persisted event, expecting two retries. notifyNow increments and writes the retry count only after the callback returns, so on a loaded runner the read could land between the second callback and its write and observe one retry. Same race as fixed for TestNotifier_Notify in #4274; observed on #4487. The subtest now waits for the persisted retry count and checks that the callback ran at least that often. Assisted-by: AI --- network/dag/notifier_test.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/network/dag/notifier_test.go b/network/dag/notifier_test.go index e8e91e52b..27c1ebbef 100644 --- a/network/dag/notifier_test.go +++ b/network/dag/notifier_test.go @@ -455,18 +455,23 @@ func TestNotifier_VariousFlows(t *testing.T) { s.Notify(event) + // counter.N is incremented by the receiver callback, but notifyNow persists + // the updated event (Retries) only after the callback returns, and the next + // retry follows within tens of milliseconds. Wait for the persisted retry + // count instead of the in-memory counter, otherwise the read may observe + // the event before the second retry is written. + var e *Event test.WaitFor(t, func() (bool, error) { - return counter.N.Load() == 2, nil - }, time.Second, "timeout while waiting for receiver") - - kvStore.ReadShelf(ctx, s.shelfName(), func(reader stoabs.Reader) error { - e, err := s.readEvent(reader, hash.EmptyHash()) - - assert.NoError(t, err) - assert.Equal(t, 2, e.Retries) + err := kvStore.ReadShelf(ctx, s.shelfName(), func(reader stoabs.Reader) error { + var err error + e, err = s.readEvent(reader, hash.EmptyHash()) + return err + }) + return err == nil && e != nil && e.Retries >= 2, nil + }, time.Second, "timeout while waiting for the retry to be persisted") - return nil - }) + // every persisted retry was preceded by a receiver call + assert.GreaterOrEqual(t, counter.N.Load(), int64(e.Retries)) }) t.Run("notifier marks event as finished", func(t *testing.T) {