From 6191f31508f0f96386b2919e8cf4eec6d1eb6d6a Mon Sep 17 00:00:00 2001 From: Avory Date: Wed, 27 Aug 2025 04:49:47 +0300 Subject: [PATCH] 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 --- eth/sync_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/eth/sync_test.go b/eth/sync_test.go index cad3a4732e..dc295f2790 100644 --- a/eth/sync_test.go +++ b/eth/sync_test.go @@ -88,9 +88,17 @@ func testSnapSyncDisabling(t *testing.T, ethVer uint, snapVer uint) { if err := empty.handler.downloader.BeaconSync(ethconfig.SnapSync, full.chain.CurrentBlock(), nil); err != nil { t.Fatal("sync failed:", err) } - time.Sleep(time.Second * 5) // Downloader internally has to wait a timer (3s) to be expired before exiting - - if empty.handler.snapSync.Load() { - t.Fatalf("snap sync not disabled after successful synchronisation") + // Downloader internally has to wait for a timer (3s) to be expired before + // exiting. Poll after to determine if sync is disabled. + time.Sleep(time.Second * 3) + for timeout := time.After(time.Second); ; { + select { + case <-timeout: + t.Fatalf("snap sync not disabled after successful synchronisation") + case <-time.After(100 * time.Millisecond): + if !empty.handler.snapSync.Load() { + return + } + } } }