@cryptotaxi247 / kubo / commits / 59d6a9a19

fix swarm notif tests

they were failing intermittently License: MIT Signed-off-by: Juan Batiz-Benet <juan@benet.ai>

Juan Batiz-Benet committed Jun 27, 2015 at 00:32 UTC 59d6a9a19cc2c32c4221d68c5df336efcca404c0
2 files changed +23 -19
p2p/net/swarm/swarm_notif_test.go
+22 -18
@@ -11,8 +11,6 @@ import (
11 )
12
13 func TestNotifications(t *testing.T) {
14 - t.Parallel()
15 -
14 ctx := context.Background()
15 swarms := makeSwarms(ctx, t, 5)
16 defer func() {
@@ -44,24 +42,30 @@ func TestNotifications(t *testing.T) {
42 continue
43 }
44
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
62 }
62 - t.Error("connection not found", c)
63 }
64 - }()
64 + if !found {
65 + t.Error("connection not found")
66 + }
67 + }
68 +
69 }
70 }
71
p2p/net/swarm/swarm_test.go
+1 -1
@@ -325,6 +325,6 @@ func TestFilterBounds(t *testing.T) {
325 case <-time.After(time.Second):
326 t.Fatal("should have gotten connection")
327 case <-conns:
328 - fmt.Println("got connect")
328 + t.Log("got connect")
329 }
330 }