diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-06-12 19:36:44 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-06-15 14:22:37 +0800 |
commit | 30a9939388ac738aba39eb64c287bbf9bbda91c9 (patch) | |
tree | 1a007d0b650c1e2bc29fc7ddd7118db6d9f40ab7 /eth/downloader | |
parent | fc7abd98865f3bdc6cc36258026db98a649cd577 (diff) | |
download | dexon-30a9939388ac738aba39eb64c287bbf9bbda91c9.tar dexon-30a9939388ac738aba39eb64c287bbf9bbda91c9.tar.gz dexon-30a9939388ac738aba39eb64c287bbf9bbda91c9.tar.bz2 dexon-30a9939388ac738aba39eb64c287bbf9bbda91c9.tar.lz dexon-30a9939388ac738aba39eb64c287bbf9bbda91c9.tar.xz dexon-30a9939388ac738aba39eb64c287bbf9bbda91c9.tar.zst dexon-30a9939388ac738aba39eb64c287bbf9bbda91c9.zip |
eth/downloader: sanity test for multi peer syncs
Diffstat (limited to 'eth/downloader')
-rw-r--r-- | eth/downloader/downloader_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index 6cd141ef7..9803ae534 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -309,6 +309,37 @@ func TestThrottling(t *testing.T) { } } +// Tests that synchronisation from multiple peers works as intended (multi thread sanity test). +func TestMultiSynchronisation(t *testing.T) { + // Create various peers with various parts of the chain + targetPeers := 16 + targetBlocks := targetPeers*blockCacheLimit - 15 + + hashes := createHashes(targetBlocks, knownHash) + blocks := createBlocksFromHashes(hashes) + + tester := newTester() + for i := 0; i < targetPeers; i++ { + id := fmt.Sprintf("peer #%d", i) + tester.newPeer(id, hashes[i*blockCacheLimit:], blocks) + } + // Synchronise with the middle peer and make sure half of the blocks were retrieved + id := fmt.Sprintf("peer #%d", targetPeers/2) + if err := tester.sync(id); err != nil { + t.Fatalf("failed to synchronise blocks: %v", err) + } + if imported := len(tester.ownBlocks); imported != len(tester.peerHashes[id]) { + t.Fatalf("synchronised block mismatch: have %v, want %v", imported, len(tester.peerHashes[id])) + } + // Synchronise with the best peer and make sure everything is retrieved + if err := tester.sync("peer #0"); err != nil { + t.Fatalf("failed to synchronise blocks: %v", err) + } + if imported := len(tester.ownBlocks); imported != targetBlocks+1 { + t.Fatalf("synchronised block mismatch: have %v, want %v", imported, targetBlocks+1) + } +} + // Tests that if a peer returns an invalid chain with a block pointing to a non- // existing parent, it is correctly detected and handled. func TestNonExistingParentAttack(t *testing.T) { |