mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-14 03:56:36 +00:00
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 <lightclient@protonmail.com>
This commit is contained in:
parent
eab5c929a2
commit
6191f31508
1 changed files with 12 additions and 4 deletions
|
|
@ -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 {
|
if err := empty.handler.downloader.BeaconSync(ethconfig.SnapSync, full.chain.CurrentBlock(), nil); err != nil {
|
||||||
t.Fatal("sync failed:", err)
|
t.Fatal("sync failed:", err)
|
||||||
}
|
}
|
||||||
time.Sleep(time.Second * 5) // Downloader internally has to wait a timer (3s) to be expired before exiting
|
// Downloader internally has to wait for a timer (3s) to be expired before
|
||||||
|
// exiting. Poll after to determine if sync is disabled.
|
||||||
if empty.handler.snapSync.Load() {
|
time.Sleep(time.Second * 3)
|
||||||
t.Fatalf("snap sync not disabled after successful synchronisation")
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue