mock: fix notif test
License: MIT Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
Juan Batiz-Benet committed
Jun 26, 2015 at 23:57 UTC
f796615e10348520111edf1566b17b3b812192d3
1 file changed
+21
-15
p2p/net/mock/mock_notif_test.go
+21
-15
@@ -43,24 +43,30 @@ func TestNotifications(t *testing.T) {
43
for i, s := range nets {
44
n := notifiees[i]
45
for _, s2 := range nets {
46
- cos := s.ConnsToPeer(s2.LocalPeer())
47
- func() {
48
- for i := 0; i < len(cos); i++ {
49
- var c inet.Conn
50
- select {
51
- case c = <-n.connected:
52
- case <-time.After(timeout):
53
- t.Fatal("timeout")
54
- }
55
- for _, c2 := range cos {
56
- if c == c2 {
57
- t.Log("got notif for conn")
58
- return
59
- }
46
+ var actual []inet.Conn
47
+ for len(s.ConnsToPeer(s2.LocalPeer())) != len(actual) {
48
+ select {
49
+ case c := <-n.connected:
50
+ actual = append(actual, c)
51
+ case <-time.After(timeout):
52
+ t.Fatal("timeout")
53
+ }
54
+ }
55
+
56
+ expect := s.ConnsToPeer(s2.LocalPeer())
57
+ for _, c1 := range actual {
58
+ found := false
59
+ for _, c2 := range expect {
60
+ if c1 == c2 {
61
+ found = true
62
+ break
63
}
64
+ }
65
+ if !found {
66
t.Error("connection not found")
67
}
63
- }()
68
+ }
69
+
70
}
71
}
72