downloader: fix race condition in tests
This commit is contained in:
parent
38310f9022
commit
108033ebc6
|
@ -67,7 +67,7 @@ type downloadTester struct {
|
|||
}
|
||||
|
||||
// newTester creates a new downloader test mocker.
|
||||
func newTester() *downloadTester {
|
||||
func newTester(mode SyncMode) *downloadTester {
|
||||
tester := &downloadTester{
|
||||
genesis: testGenesis,
|
||||
peerDb: testDB,
|
||||
|
@ -87,7 +87,11 @@ func newTester() *downloadTester {
|
|||
tester.stateDb = rawdb.NewMemoryDatabase()
|
||||
tester.stateDb.Put(testGenesis.Root().Bytes(), []byte{0x00})
|
||||
|
||||
tester.downloader = New(0, tester.stateDb, trie.NewSyncBloom(1, tester.stateDb), new(event.TypeMux), tester, nil, tester.dropPeer)
|
||||
var syncBloom *trie.SyncBloom
|
||||
if mode == FastSync {
|
||||
syncBloom = trie.NewSyncBloom(1, tester.stateDb)
|
||||
}
|
||||
tester.downloader = New(0, tester.stateDb, syncBloom, new(event.TypeMux), tester, nil, tester.dropPeer)
|
||||
return tester
|
||||
}
|
||||
|
||||
|
@ -529,7 +533,7 @@ func TestCanonicalSynchronisation65Light(t *testing.T) {
|
|||
func testCanonicalSynchronisation(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
defer tester.terminate()
|
||||
|
||||
// Create a small enough block chain to download
|
||||
|
@ -552,7 +556,7 @@ func TestThrottling65Fast(t *testing.T) { testThrottling(t, 65, FastSync) }
|
|||
|
||||
func testThrottling(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
|
||||
// Create a long block chain to download and the tester
|
||||
targetBlocks := testChainBase.len() - 1
|
||||
|
@ -637,7 +641,7 @@ func TestForkedSync65Light(t *testing.T) { testForkedSync(t, 65, LightSync) }
|
|||
func testForkedSync(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
defer tester.terminate()
|
||||
|
||||
chainA := testChainForkLightA.shorten(testChainBase.len() + 80)
|
||||
|
@ -668,7 +672,7 @@ func TestHeavyForkedSync65Light(t *testing.T) { testHeavyForkedSync(t, 65, Light
|
|||
func testHeavyForkedSync(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
defer tester.terminate()
|
||||
|
||||
chainA := testChainForkLightA.shorten(testChainBase.len() + 80)
|
||||
|
@ -701,7 +705,7 @@ func TestBoundedForkedSync65Light(t *testing.T) { testBoundedForkedSync(t, 65, L
|
|||
func testBoundedForkedSync(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
defer tester.terminate()
|
||||
|
||||
chainA := testChainForkLightA
|
||||
|
@ -732,7 +736,7 @@ func TestBoundedHeavyForkedSync65Light(t *testing.T) { testBoundedHeavyForkedSyn
|
|||
|
||||
func testBoundedHeavyForkedSync(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
|
||||
// Create a long enough forked chain
|
||||
chainA := testChainForkLightA
|
||||
|
@ -758,7 +762,7 @@ func testBoundedHeavyForkedSync(t *testing.T, protocol uint, mode SyncMode) {
|
|||
func TestInactiveDownloader63(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(FullSync)
|
||||
defer tester.terminate()
|
||||
|
||||
// Check that neither block headers nor bodies are accepted
|
||||
|
@ -783,7 +787,7 @@ func TestCancel65Light(t *testing.T) { testCancel(t, 65, LightSync) }
|
|||
func testCancel(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
defer tester.terminate()
|
||||
|
||||
chain := testChainBase.shorten(MaxHeaderFetch)
|
||||
|
@ -814,7 +818,7 @@ func TestMultiSynchronisation65Light(t *testing.T) { testMultiSynchronisation(t,
|
|||
func testMultiSynchronisation(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
defer tester.terminate()
|
||||
|
||||
// Create various peers with various parts of the chain
|
||||
|
@ -842,7 +846,7 @@ func TestMultiProtoSynchronisation65Light(t *testing.T) { testMultiProtoSync(t,
|
|||
func testMultiProtoSync(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
defer tester.terminate()
|
||||
|
||||
// Create a small enough block chain to download
|
||||
|
@ -879,7 +883,7 @@ func TestEmptyShortCircuit65Light(t *testing.T) { testEmptyShortCircuit(t, 65, L
|
|||
func testEmptyShortCircuit(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
defer tester.terminate()
|
||||
|
||||
// Create a block chain to download
|
||||
|
@ -931,7 +935,7 @@ func TestMissingHeaderAttack65Light(t *testing.T) { testMissingHeaderAttack(t, 6
|
|||
func testMissingHeaderAttack(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
defer tester.terminate()
|
||||
|
||||
chain := testChainBase.shorten(blockCacheMaxItems - 15)
|
||||
|
@ -961,7 +965,7 @@ func TestShiftedHeaderAttack65Light(t *testing.T) { testShiftedHeaderAttack(t, 6
|
|||
func testShiftedHeaderAttack(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
defer tester.terminate()
|
||||
|
||||
chain := testChainBase.shorten(blockCacheMaxItems - 15)
|
||||
|
@ -993,7 +997,7 @@ func TestInvalidHeaderRollback65Fast(t *testing.T) { testInvalidHeaderRollback(t
|
|||
func testInvalidHeaderRollback(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
|
||||
// Create a small enough block chain to download
|
||||
targetBlocks := 3*fsHeaderSafetyNet + 256 + fsMinFullBlocks
|
||||
|
@ -1087,7 +1091,7 @@ func TestHighTDStarvationAttack65Light(t *testing.T) { testHighTDStarvationAttac
|
|||
func testHighTDStarvationAttack(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
|
||||
chain := testChainBase.shorten(1)
|
||||
tester.newPeer("attack", protocol, chain)
|
||||
|
@ -1126,7 +1130,7 @@ func testBlockHeaderAttackerDropping(t *testing.T, protocol uint) {
|
|||
{errCancelContentProcessing, false}, // Synchronisation was canceled, origin may be innocent, don't drop
|
||||
}
|
||||
// Run the tests and check disconnection status
|
||||
tester := newTester()
|
||||
tester := newTester(FullSync)
|
||||
defer tester.terminate()
|
||||
chain := testChainBase.shorten(1)
|
||||
|
||||
|
@ -1160,7 +1164,7 @@ func TestSyncProgress65Light(t *testing.T) { testSyncProgress(t, 65, LightSync)
|
|||
func testSyncProgress(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
defer tester.terminate()
|
||||
chain := testChainBase.shorten(blockCacheMaxItems - 15)
|
||||
|
||||
|
@ -1242,7 +1246,7 @@ func TestForkedSyncProgress65Light(t *testing.T) { testForkedSyncProgress(t, 65,
|
|||
func testForkedSyncProgress(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
defer tester.terminate()
|
||||
chainA := testChainForkLightA.shorten(testChainBase.len() + MaxHeaderFetch)
|
||||
chainB := testChainForkLightB.shorten(testChainBase.len() + MaxHeaderFetch)
|
||||
|
@ -1316,7 +1320,7 @@ func TestFailedSyncProgress65Light(t *testing.T) { testFailedSyncProgress(t, 65,
|
|||
func testFailedSyncProgress(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
defer tester.terminate()
|
||||
chain := testChainBase.shorten(blockCacheMaxItems - 15)
|
||||
|
||||
|
@ -1387,7 +1391,7 @@ func TestFakedSyncProgress65Light(t *testing.T) { testFakedSyncProgress(t, 65, L
|
|||
func testFakedSyncProgress(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
defer tester.terminate()
|
||||
chain := testChainBase.shorten(blockCacheMaxItems - 15)
|
||||
|
||||
|
@ -1462,12 +1466,12 @@ func TestDeliverHeadersHang65Light(t *testing.T) { testDeliverHeadersHang(t, 65,
|
|||
func testDeliverHeadersHang(t *testing.T, protocol uint, mode SyncMode) {
|
||||
t.Parallel()
|
||||
|
||||
master := newTester()
|
||||
master := newTester(mode)
|
||||
defer master.terminate()
|
||||
chain := testChainBase.shorten(15)
|
||||
|
||||
for i := 0; i < 200; i++ {
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
tester.peerDb = master.peerDb
|
||||
tester.newPeer("peer", protocol, chain)
|
||||
|
||||
|
@ -1622,7 +1626,7 @@ func testCheckpointEnforcement(t *testing.T, protocol uint, mode SyncMode) {
|
|||
t.Parallel()
|
||||
|
||||
// Create a new tester with a particular hard coded checkpoint block
|
||||
tester := newTester()
|
||||
tester := newTester(mode)
|
||||
defer tester.terminate()
|
||||
|
||||
tester.downloader.checkpoint = uint64(fsMinFullBlocks) + 256
|
||||
|
|
Loading…
Reference in New Issue