Skip to content

Commit 43901c9

Browse files
committed
eth/downloader: fix priority queue reset, add throttling test
1 parent 45f8304 commit 43901c9

File tree

6 files changed

+111
-21
lines changed

6 files changed

+111
-21
lines changed

Godeps/Godeps.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/prque.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/prque_test.go

Lines changed: 36 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/sstack.go

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/sstack_test.go

Lines changed: 23 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eth/downloader/downloader_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,51 @@ func TestTaking(t *testing.T) {
181181
t.Error("expected to take 1000, got", len(bs1))
182182
}
183183
}
184+
185+
func TestThrottling(t *testing.T) {
186+
minDesiredPeerCount = 4
187+
blockTtl = 1 * time.Second
188+
189+
targetBlocks := 4 * blockCacheLimit
190+
hashes := createHashes(0, targetBlocks)
191+
blocks := createBlocksFromHashes(hashes)
192+
tester := newTester(t, hashes, blocks)
193+
194+
tester.newPeer("peer1", big.NewInt(10000), hashes[0])
195+
tester.newPeer("peer2", big.NewInt(0), common.Hash{})
196+
tester.badBlocksPeer("peer3", big.NewInt(0), common.Hash{})
197+
tester.badBlocksPeer("peer4", big.NewInt(0), common.Hash{})
198+
199+
// Concurrently download and take the blocks
200+
errc := make(chan error, 1)
201+
go func() {
202+
errc <- tester.sync("peer1", hashes[0])
203+
}()
204+
205+
done := make(chan struct{})
206+
took := []*types.Block{}
207+
go func() {
208+
for {
209+
select {
210+
case <-done:
211+
took = append(took, tester.downloader.TakeBlocks()...)
212+
done <- struct{}{}
213+
return
214+
default:
215+
took = append(took, tester.downloader.TakeBlocks()...)
216+
}
217+
}
218+
}()
219+
220+
// Synchronize the two threads and verify
221+
err := <-errc
222+
done <- struct{}{}
223+
<-done
224+
225+
if err != nil {
226+
t.Fatalf("failed to synchronize blocks: %v", err)
227+
}
228+
if len(took) != targetBlocks {
229+
t.Fatalf("downloaded block mismatch: have %v, want %v", len(took), targetBlocks)
230+
}
231+
}

0 commit comments

Comments
 (0)