diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-05-07 19:40:50 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-05-07 19:40:50 +0800 |
commit | 43901c92825389b694fb5488c520cf5122f022de (patch) | |
tree | cb3954ab520d201f80764e81fb574d34b5b9c0f1 /eth/downloader | |
parent | 45f8304f3c44e5379c7e30ab144d73e591e270af (diff) | |
download | go-tangerine-43901c92825389b694fb5488c520cf5122f022de.tar go-tangerine-43901c92825389b694fb5488c520cf5122f022de.tar.gz go-tangerine-43901c92825389b694fb5488c520cf5122f022de.tar.bz2 go-tangerine-43901c92825389b694fb5488c520cf5122f022de.tar.lz go-tangerine-43901c92825389b694fb5488c520cf5122f022de.tar.xz go-tangerine-43901c92825389b694fb5488c520cf5122f022de.tar.zst go-tangerine-43901c92825389b694fb5488c520cf5122f022de.zip |
eth/downloader: fix priority queue reset, add throttling test
Diffstat (limited to 'eth/downloader')
-rw-r--r-- | eth/downloader/downloader_test.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index 11834d788..bd439d96a 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -181,3 +181,51 @@ func TestTaking(t *testing.T) { t.Error("expected to take 1000, got", len(bs1)) } } + +func TestThrottling(t *testing.T) { + minDesiredPeerCount = 4 + blockTtl = 1 * time.Second + + targetBlocks := 4 * blockCacheLimit + hashes := createHashes(0, targetBlocks) + blocks := createBlocksFromHashes(hashes) + tester := newTester(t, hashes, blocks) + + tester.newPeer("peer1", big.NewInt(10000), hashes[0]) + tester.newPeer("peer2", big.NewInt(0), common.Hash{}) + tester.badBlocksPeer("peer3", big.NewInt(0), common.Hash{}) + tester.badBlocksPeer("peer4", big.NewInt(0), common.Hash{}) + + // Concurrently download and take the blocks + errc := make(chan error, 1) + go func() { + errc <- tester.sync("peer1", hashes[0]) + }() + + done := make(chan struct{}) + took := []*types.Block{} + go func() { + for { + select { + case <-done: + took = append(took, tester.downloader.TakeBlocks()...) + done <- struct{}{} + return + default: + took = append(took, tester.downloader.TakeBlocks()...) + } + } + }() + + // Synchronize the two threads and verify + err := <-errc + done <- struct{}{} + <-done + + if err != nil { + t.Fatalf("failed to synchronize blocks: %v", err) + } + if len(took) != targetBlocks { + t.Fatalf("downloaded block mismatch: have %v, want %v", len(took), targetBlocks) + } +} |