From cee751a1edc34a3f04be13e794e504f59ac11fc0 Mon Sep 17 00:00:00 2001 From: Delweng Date: Fri, 27 Feb 2026 19:51:01 +0800 Subject: [PATCH] eth: fix the flaky test of TestSnapSyncDisabling68 (#33896) fix the flaky test found in https://ci.appveyor.com/project/ethereum/go-ethereum/builds/53601688/job/af5ccvufpm9usq39 1. increase the timeout from 3+1s to 15s, and use timer instead of sleep(in the CI env, it may need more time to sync the 1024 blocks) 2. add `synced.Load()` to ensure the full async chain is finished Signed-off-by: Delweng --- eth/sync_test.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/eth/sync_test.go b/eth/sync_test.go index 509b836f82..dad816229a 100644 --- a/eth/sync_test.go +++ b/eth/sync_test.go @@ -82,15 +82,18 @@ func testSnapSyncDisabling(t *testing.T, ethVer uint, snapVer uint) { if err := empty.handler.downloader.BeaconSync(full.chain.CurrentBlock(), nil); err != nil { t.Fatal("sync failed:", err) } - // 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); ; { + // Snap sync and mode switching happen asynchronously, poll for completion. + timeout := time.NewTimer(15 * time.Second) + tick := time.NewTicker(100 * time.Millisecond) + defer timeout.Stop() + defer tick.Stop() + + for { select { - case <-timeout: + case <-timeout.C: t.Fatalf("snap sync not disabled after successful synchronisation") - case <-time.After(100 * time.Millisecond): - if empty.handler.downloader.ConfigSyncMode() == ethconfig.FullSync { + case <-tick.C: + if empty.handler.synced.Load() && empty.handler.downloader.ConfigSyncMode() == ethconfig.FullSync { return } }