From 80188421fd0ca60710d45a3872cf6f4e44fc2fa4 Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Wed, 3 Jul 2024 12:43:52 +0200 Subject: [PATCH] tests: fix unstable test --- eth/sync_test.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/eth/sync_test.go b/eth/sync_test.go index 195d2fd2ae..72d018527e 100644 --- a/eth/sync_test.go +++ b/eth/sync_test.go @@ -112,7 +112,14 @@ func testChainSyncWithBlobs(t *testing.T, mode downloader.SyncMode, preCancunBlk cancunTime := (preCancunBlks + 1) * 10 config.CancunTime = &cancunTime - // Create a full handler and ensure snap sync ends up disabled + // Create an empty handler + empty := newTestParliaHandlerAfterCancun(t, &config, mode, 0, 0) + defer empty.close() + if downloader.SnapSync == mode && !empty.handler.snapSync.Load() { + t.Fatalf("snap sync disabled on pristine blockchain") + } + + // Create a full handler full := newTestParliaHandlerAfterCancun(t, &config, mode, preCancunBlks, postCancunBlks) defer full.close() if downloader.SnapSync == mode && full.handler.snapSync.Load() { @@ -122,13 +129,6 @@ func testChainSyncWithBlobs(t *testing.T, mode downloader.SyncMode, preCancunBlk // check blocks and blobs checkChainWithBlobs(t, full.chain, preCancunBlks, postCancunBlks) - // Create an empty handler and ensure it's in snap sync mode - empty := newTestParliaHandlerAfterCancun(t, &config, mode, 0, 0) - defer empty.close() - if downloader.SnapSync == mode && !empty.handler.snapSync.Load() { - t.Fatalf("snap sync disabled on pristine blockchain") - } - // Sync up the two handlers via both `eth` and `snap` ethVer := uint(eth.ETH68) snapVer := uint(snap.SNAP1) @@ -151,8 +151,6 @@ func testChainSyncWithBlobs(t *testing.T, mode downloader.SyncMode, preCancunBlk go full.handler.runEthPeer(fullPeerEth, func(peer *eth.Peer) error { return eth.Handle((*ethHandler)(full.handler), peer) }) - // Wait a bit for the above handlers to start - time.Sleep(250 * time.Millisecond) emptyPipeSnap, fullPipeSnap := p2p.MsgPipe() defer emptyPipeSnap.Close() @@ -167,14 +165,17 @@ func testChainSyncWithBlobs(t *testing.T, mode downloader.SyncMode, preCancunBlk go full.handler.runSnapExtension(fullPeerSnap, func(peer *snap.Peer) error { return snap.Handle((*snapHandler)(full.handler), peer) }) - // Wait a bit for the above handlers to start - time.Sleep(250 * time.Millisecond) - // Check that snap sync was disabled + for empty.handler.peers.snapLen() < 1 { + // Wait a bit for the above handlers to start + time.Sleep(100 * time.Millisecond) + } + op := peerToSyncOp(mode, empty.handler.peers.peerWithHighestTD()) if err := empty.handler.doSync(op); err != nil { t.Fatal("sync failed:", err) } + // Check that snap sync was disabled if !empty.handler.synced.Load() { t.Fatalf("full sync not done after successful synchronisation") }