From 7905ef67e9fd5dc6421d245ff11271f5551cf3c2 Mon Sep 17 00:00:00 2001 From: Ljubisa Gacevic Date: Tue, 4 Nov 2025 14:57:51 +0100 Subject: [PATCH] test(puller): fix race condition in TestSyncIntervals Wait for interval persistence using spinlock.Wait() instead of fixed sleep. This fixes the flaky 'storage: not found' error in TestSyncIntervals/0,_50_-_2_calls by polling for the interval to appear in storage rather than checking immediately after sync operations complete. The test was failing because checkIntervals() was checking for persisted intervals immediately after sync calls completed, but interval persistence happens asynchronously. Using spinlock.Wait() makes the test more deterministic and handles timing variations better than a fixed time.Sleep(). --- pkg/puller/puller_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/puller/puller_test.go b/pkg/puller/puller_test.go index 29687138b9c..c23d5b006de 100644 --- a/pkg/puller/puller_test.go +++ b/pkg/puller/puller_test.go @@ -197,7 +197,7 @@ func TestSyncIntervals(t *testing.T) { kad.Trigger() waitSyncCalledBins(t, pullsync, addr, 1) waitSyncStart(t, pullsync, addr, tc.replies[len(tc.replies)-1].Start) - time.Sleep(100 * time.Millisecond) + checkIntervals(t, st, addr, tc.intervals, 1) }) } @@ -560,8 +560,13 @@ func TestPeerGone(t *testing.T) { func checkIntervals(t *testing.T, s storage.StateStorer, addr swarm.Address, expInterval string, bin uint8) { t.Helper() key := puller.PeerIntervalKey(addr, bin) - i := &intervalstore.Intervals{} - err := s.Get(key, i) + var i *intervalstore.Intervals + + err := spinlock.Wait(time.Second, func() bool { + i = &intervalstore.Intervals{} + err := s.Get(key, i) + return err == nil + }) if err != nil { t.Fatalf("error getting interval for bin %d: %v", bin, err) }