Skip to content

Commit a34304f

Browse files
lidelgammazero
andauthored
fix: flaky TestSessionBetweenPeers with shuffle enabled (#1022)
* fix: flaky TestSessionBetweenPeers with shuffle enabled The test was flaky when run with -shuffle=on because of a race condition in message counting. After fetching the first block (cids[0]), which triggers a broadcast want-have to all peers and then a CANCEL when received, the test immediately continued fetching more blocks. During this time, the session's internal timers (idle tick or periodic search) could fire and cause a rebroadcast of wants before the test checked message counts on uninvolved nodes. With test shuffling, goroutine scheduling changes made this timing issue more likely, causing uninvolved nodes to sometimes receive 3 messages instead of the expected 2. Adding a small delay after the first block fetch ensures the CANCEL is fully processed and the session stabilizes before continuing, preventing the race condition. * Update bitswap/client/bitswap_with_sessions_test.go --------- Co-authored-by: Andrew Gillis <[email protected]>
1 parent 3a7437a commit a34304f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

bitswap/client/bitswap_with_sessions_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ func TestSessionBetweenPeers(t *testing.T) {
203203
if _, err := ses.GetBlock(ctx, cids[0]); err != nil {
204204
t.Fatal(err)
205205
}
206+
207+
// Wait briefly to ensure the CANCEL for cids[0] is fully processed
208+
// before continuing with more requests that might trigger rebroadcasts
209+
time.Sleep(50 * time.Millisecond)
210+
206211
blks = blks[1:]
207212
cids = cids[1:]
208213

0 commit comments

Comments
 (0)