Skip to content

Commit 6191f31

Browse files
eth: replace hardcoded sleep with polling loop in snap sync test (#32499)
Replace hardcoded 5-second sleep with polling loop that actively checks snap sync state. This approach is already used in other project tests (like account_cache_test.go) and provides better reliability by: - Reducing flaky behavior on slower systems - Finishing early when sync completes quickly - Using 1-second timeout with 100ms polling intervals --------- Co-authored-by: lightclient <[email protected]>
1 parent eab5c92 commit 6191f31

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

eth/sync_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,17 @@ func testSnapSyncDisabling(t *testing.T, ethVer uint, snapVer uint) {
8888
if err := empty.handler.downloader.BeaconSync(ethconfig.SnapSync, full.chain.CurrentBlock(), nil); err != nil {
8989
t.Fatal("sync failed:", err)
9090
}
91-
time.Sleep(time.Second * 5) // Downloader internally has to wait a timer (3s) to be expired before exiting
92-
93-
if empty.handler.snapSync.Load() {
94-
t.Fatalf("snap sync not disabled after successful synchronisation")
91+
// Downloader internally has to wait for a timer (3s) to be expired before
92+
// exiting. Poll after to determine if sync is disabled.
93+
time.Sleep(time.Second * 3)
94+
for timeout := time.After(time.Second); ; {
95+
select {
96+
case <-timeout:
97+
t.Fatalf("snap sync not disabled after successful synchronisation")
98+
case <-time.After(100 * time.Millisecond):
99+
if !empty.handler.snapSync.Load() {
100+
return
101+
}
102+
}
95103
}
96104
}

0 commit comments

Comments
 (0)