aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/server_test.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-05-03 19:30:51 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2016-05-03 19:30:51 +0800
commit258cc73ea970890a5b75bf27197c3a6667f3bc5a (patch)
tree451b71e96d59d7e8a91420df90eb11dd2c4bdd87 /p2p/server_test.go
parent79b7b5eeaad68c390f658b085eb9cfec74a3509c (diff)
parent81106719601c6eb0fa9e9421262569c16e3c2fde (diff)
downloaddexon-258cc73ea970890a5b75bf27197c3a6667f3bc5a.tar
dexon-258cc73ea970890a5b75bf27197c3a6667f3bc5a.tar.gz
dexon-258cc73ea970890a5b75bf27197c3a6667f3bc5a.tar.bz2
dexon-258cc73ea970890a5b75bf27197c3a6667f3bc5a.tar.lz
dexon-258cc73ea970890a5b75bf27197c3a6667f3bc5a.tar.xz
dexon-258cc73ea970890a5b75bf27197c3a6667f3bc5a.tar.zst
dexon-258cc73ea970890a5b75bf27197c3a6667f3bc5a.zip
Merge pull request #2510 from fjl/p2p-fixups
p2p/discover: prevent bonding self
Diffstat (limited to 'p2p/server_test.go')
-rw-r--r--p2p/server_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/p2p/server_test.go b/p2p/server_test.go
index 02d1c8e01..b437ac367 100644
--- a/p2p/server_test.go
+++ b/p2p/server_test.go
@@ -235,6 +235,56 @@ func TestServerTaskScheduling(t *testing.T) {
}
}
+// This test checks that Server doesn't drop tasks,
+// even if newTasks returns more than the maximum number of tasks.
+func TestServerManyTasks(t *testing.T) {
+ alltasks := make([]task, 300)
+ for i := range alltasks {
+ alltasks[i] = &testTask{index: i}
+ }
+
+ var (
+ srv = &Server{quit: make(chan struct{}), ntab: fakeTable{}, running: true}
+ done = make(chan *testTask)
+ start, end = 0, 0
+ )
+ defer srv.Stop()
+ srv.loopWG.Add(1)
+ go srv.run(taskgen{
+ newFunc: func(running int, peers map[discover.NodeID]*Peer) []task {
+ start, end = end, end+maxActiveDialTasks+10
+ if end > len(alltasks) {
+ end = len(alltasks)
+ }
+ return alltasks[start:end]
+ },
+ doneFunc: func(tt task) {
+ done <- tt.(*testTask)
+ },
+ })
+
+ doneset := make(map[int]bool)
+ timeout := time.After(2 * time.Second)
+ for len(doneset) < len(alltasks) {
+ select {
+ case tt := <-done:
+ if doneset[tt.index] {
+ t.Errorf("task %d got done more than once", tt.index)
+ } else {
+ doneset[tt.index] = true
+ }
+ case <-timeout:
+ t.Errorf("%d of %d tasks got done within 2s", len(doneset), len(alltasks))
+ for i := 0; i < len(alltasks); i++ {
+ if !doneset[i] {
+ t.Logf("task %d not done", i)
+ }
+ }
+ return
+ }
+ }
+}
+
type taskgen struct {
newFunc func(running int, peers map[discover.NodeID]*Peer) []task
doneFunc func(task)