From e9acf48a25feb9719a795f49977f5e667ba07ded Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Fri, 15 May 2026 23:46:52 +0800 Subject: [PATCH] test(eth): stabilize fast sync disabling test Replace the fixed sleep and one-shot synchronise call with a timeout-based retry loop so the test tolerates CI scheduling variance. Add protocol manager cleanup to avoid leaking background work between test runs. --- eth/sync_test.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/eth/sync_test.go b/eth/sync_test.go index 8c25a98190b4..06d2c69a6364 100644 --- a/eth/sync_test.go +++ b/eth/sync_test.go @@ -31,11 +31,13 @@ import ( func TestFastSyncDisabling(t *testing.T) { // Create a pristine protocol manager, check that fast sync is left enabled pmEmpty, _ := newTestProtocolManagerMust(t, downloader.FastSync, 0, nil, nil) + defer pmEmpty.Stop() if atomic.LoadUint32(&pmEmpty.snapSync) == 0 { t.Fatalf("snap sync disabled on pristine blockchain") } // Create a full protocol manager, check that snap sync gets disabled pmFull, _ := newTestProtocolManagerMust(t, downloader.FastSync, 1024, nil, nil) + defer pmFull.Stop() if atomic.LoadUint32(&pmFull.snapSync) == 1 { t.Fatalf("snap sync not disabled on non-empty blockchain") } @@ -45,11 +47,19 @@ func TestFastSyncDisabling(t *testing.T) { go pmFull.handle(pmFull.newPeer(63, p2p.NewPeer(enode.ID{}, "empty", nil), io2)) go pmEmpty.handle(pmEmpty.newPeer(63, p2p.NewPeer(enode.ID{}, "full", nil), io1)) - time.Sleep(250 * time.Millisecond) - pmEmpty.synchronise(pmEmpty.peers.BestPeer()) + deadline := time.After(15 * time.Second) + ticker := time.NewTicker(100 * time.Millisecond) + defer ticker.Stop() - // Check that snap sync was disabled - if atomic.LoadUint32(&pmEmpty.snapSync) == 1 { - t.Fatalf("snap sync not disabled after successful synchronisation") + for { + if atomic.LoadUint32(&pmEmpty.snapSync) == 0 { + return + } + select { + case <-deadline: + t.Fatalf("snap sync not disabled after successful synchronisation") + case <-ticker.C: + pmEmpty.synchronise(pmEmpty.peers.BestPeer()) + } } }