eth/downloader: fix occasional fast sync critical section test fails

This commit is contained in:
Péter Szilágyi 2016-06-13 13:01:19 +03:00
parent ce88d41907
commit 783289068a

@ -1824,13 +1824,15 @@ func testFastCriticalRestarts(t *testing.T, protocol int) {
for i := 0; i < fsPivotInterval; i++ { for i := 0; i < fsPivotInterval; i++ {
tester.peerMissingStates["peer"][headers[hashes[fsMinFullBlocks+i]].Root] = true tester.peerMissingStates["peer"][headers[hashes[fsMinFullBlocks+i]].Root] = true
} }
tester.downloader.dropPeer = func(id string) {} // We reuse the same "faulty" peer throughout the test
// Synchronise with the peer a few times and make sure they fail until the retry limit // Synchronise with the peer a few times and make sure they fail until the retry limit
for i := 0; i < fsCriticalTrials; i++ { for i := 0; i < fsCriticalTrials; i++ {
// Attempt a sync and ensure it fails properly // Attempt a sync and ensure it fails properly
if err := tester.sync("peer", nil, FastSync); err == nil { if err := tester.sync("peer", nil, FastSync); err == nil {
t.Fatalf("failing fast sync succeeded: %v", err) t.Fatalf("failing fast sync succeeded: %v", err)
} }
time.Sleep(500 * time.Millisecond) // Make sure no in-flight requests remain time.Sleep(100 * time.Millisecond) // Make sure no in-flight requests remain
// If it's the first failure, pivot should be locked => reenable all others to detect pivot changes // If it's the first failure, pivot should be locked => reenable all others to detect pivot changes
if i == 0 { if i == 0 {