mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
eth/downloader: fix flaky sync tests
TestSkeletonSyncRetrievals announces a new head mid-test and ignores the Sync return value. Head events arriving while the previous sync cycle is tearing down are rejected (see #27397), so the announcement can be silently lost and the persisted progress never reaches the expected head. Retry the announcement until the syncer accepts it. testEmptyShortCircuit and four sibling tests wait for a full-chain sync with a one-shot 3s failsafe that an idle -race run already half consumes. Raise the failsafes to 30s; the selects still return the moment the sync notification arrives. Signed-off-by: Mikhail Kuznetsov <mikhail.n.kuznetsov@gmail.com>
This commit is contained in:
parent
3ab52d837d
commit
0117b01ec4
2 changed files with 18 additions and 11 deletions
|
|
@ -456,8 +456,8 @@ func testCanonSync(t *testing.T, protocol uint, mode SyncMode, snapV2 bool) {
|
||||||
select {
|
select {
|
||||||
case <-success:
|
case <-success:
|
||||||
assertOwnChain(t, tester, len(chain.blocks))
|
assertOwnChain(t, tester, len(chain.blocks))
|
||||||
case <-time.NewTimer(time.Second * 3).C:
|
case <-time.NewTimer(time.Second * 30).C:
|
||||||
t.Fatalf("Failed to sync chain in three seconds")
|
t.Fatalf("Failed to sync chain in time")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -605,8 +605,8 @@ func testEmptyShortCircuit(t *testing.T, protocol uint, mode SyncMode) {
|
||||||
HighestBlock: uint64(len(chain.blocks) - 1),
|
HighestBlock: uint64(len(chain.blocks) - 1),
|
||||||
CurrentBlock: uint64(len(chain.blocks) - 1),
|
CurrentBlock: uint64(len(chain.blocks) - 1),
|
||||||
})
|
})
|
||||||
case <-time.NewTimer(time.Second * 3).C:
|
case <-time.NewTimer(time.Second * 30).C:
|
||||||
t.Fatalf("Failed to sync chain in three seconds")
|
t.Fatalf("Failed to sync chain in time")
|
||||||
}
|
}
|
||||||
assertOwnChain(t, tester, len(chain.blocks))
|
assertOwnChain(t, tester, len(chain.blocks))
|
||||||
|
|
||||||
|
|
@ -679,8 +679,8 @@ func testBeaconSync(t *testing.T, protocol uint, mode SyncMode) {
|
||||||
if bs := int(tester.chain.CurrentBlock().Number.Uint64()) + 1; bs != len(chain.blocks) {
|
if bs := int(tester.chain.CurrentBlock().Number.Uint64()) + 1; bs != len(chain.blocks) {
|
||||||
t.Fatalf("synchronised blocks mismatch: have %v, want %v", bs, len(chain.blocks))
|
t.Fatalf("synchronised blocks mismatch: have %v, want %v", bs, len(chain.blocks))
|
||||||
}
|
}
|
||||||
case <-time.NewTimer(time.Second * 3).C:
|
case <-time.NewTimer(time.Second * 30).C:
|
||||||
t.Fatalf("Failed to sync chain in three seconds")
|
t.Fatalf("Failed to sync chain in time")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -790,8 +790,8 @@ func testSyncProgress(t *testing.T, protocol uint, mode SyncMode) {
|
||||||
CurrentBlock: uint64(len(chain.blocks)/2 - 1),
|
CurrentBlock: uint64(len(chain.blocks)/2 - 1),
|
||||||
HighestBlock: uint64(len(chain.blocks)/2 - 1),
|
HighestBlock: uint64(len(chain.blocks)/2 - 1),
|
||||||
})
|
})
|
||||||
case <-time.NewTimer(time.Second * 3).C:
|
case <-time.NewTimer(time.Second * 30).C:
|
||||||
t.Fatalf("Failed to sync chain in three seconds")
|
t.Fatalf("Failed to sync chain in time")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synchronise all the blocks and check continuation progress
|
// Synchronise all the blocks and check continuation progress
|
||||||
|
|
@ -809,8 +809,8 @@ func testSyncProgress(t *testing.T, protocol uint, mode SyncMode) {
|
||||||
CurrentBlock: uint64(len(chain.blocks) - 1),
|
CurrentBlock: uint64(len(chain.blocks) - 1),
|
||||||
HighestBlock: uint64(len(chain.blocks) - 1),
|
HighestBlock: uint64(len(chain.blocks) - 1),
|
||||||
})
|
})
|
||||||
case <-time.NewTimer(time.Second * 3).C:
|
case <-time.NewTimer(time.Second * 30).C:
|
||||||
t.Fatalf("Failed to sync chain in three seconds")
|
t.Fatalf("Failed to sync chain in time")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -922,7 +922,14 @@ func TestSkeletonSyncRetrievals(t *testing.T) {
|
||||||
endpeers = append(tt.peers, tt.newPeer)
|
endpeers = append(tt.peers, tt.newPeer)
|
||||||
}
|
}
|
||||||
if tt.newHead != nil {
|
if tt.newHead != nil {
|
||||||
skeleton.Sync(tt.newHead, nil, true)
|
// The head announcement is rejected if it arrives while the previous
|
||||||
|
// sync cycle is still tearing down (head events are dropped on the
|
||||||
|
// floor during teardown, see #27397). Retry until the syncer accepts
|
||||||
|
// the new head, otherwise the update is lost and the end state below
|
||||||
|
// is never reached.
|
||||||
|
for skeleton.Sync(tt.newHead, nil, true) != nil {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait a bit (bleah) for the second sync loop to go to idle. This might
|
// Wait a bit (bleah) for the second sync loop to go to idle. This might
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue