Skip to content

Commit

Permalink
tests: fix unstable test (#2561)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusKysel authored Jul 4, 2024
1 parent 88225c1 commit 971c0fa
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions eth/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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")
}
Expand Down

0 comments on commit 971c0fa

Please sign in to comment.