Skip to content

Commit 59d6a9a

Browse files
committedJun 27, 2015
fix swarm notif tests
they were failing intermittently License: MIT Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
1 parent f796615 commit 59d6a9a

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed
 

‎p2p/net/swarm/swarm_notif_test.go

+22-18
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
)
1212

1313
func TestNotifications(t *testing.T) {
14-
t.Parallel()
15-
1614
ctx := context.Background()
1715
swarms := makeSwarms(ctx, t, 5)
1816
defer func() {
@@ -44,24 +42,30 @@ func TestNotifications(t *testing.T) {
4442
continue
4543
}
4644

47-
cos := s.ConnectionsToPeer(s2.LocalPeer())
48-
func() {
49-
for i := 0; i < len(cos); i++ {
50-
var c inet.Conn
51-
select {
52-
case c = <-n.connected:
53-
case <-time.After(timeout):
54-
t.Fatal("timeout")
55-
}
56-
for _, c2 := range cos {
57-
if c == c2 {
58-
t.Log("got notif for conn", c)
59-
return
60-
}
45+
var actual []inet.Conn
46+
for len(s.ConnectionsToPeer(s2.LocalPeer())) != len(actual) {
47+
select {
48+
case c := <-n.connected:
49+
actual = append(actual, c)
50+
case <-time.After(timeout):
51+
t.Fatal("timeout")
52+
}
53+
}
54+
55+
expect := s.ConnectionsToPeer(s2.LocalPeer())
56+
for _, c1 := range actual {
57+
found := false
58+
for _, c2 := range expect {
59+
if c1 == c2 {
60+
found = true
61+
break
6162
}
62-
t.Error("connection not found", c)
6363
}
64-
}()
64+
if !found {
65+
t.Error("connection not found")
66+
}
67+
}
68+
6569
}
6670
}
6771

‎p2p/net/swarm/swarm_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,6 @@ func TestFilterBounds(t *testing.T) {
325325
case <-time.After(time.Second):
326326
t.Fatal("should have gotten connection")
327327
case <-conns:
328-
fmt.Println("got connect")
328+
t.Log("got connect")
329329
}
330330
}

0 commit comments

Comments
 (0)
Please sign in to comment.