Skip to content

Commit

Permalink
fix swarm notif tests
Browse files Browse the repository at this point in the history
they were failing intermittently

License: MIT
Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
  • Loading branch information
jbenet committed Jun 27, 2015
1 parent f796615 commit 59d6a9a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
40 changes: 22 additions & 18 deletions p2p/net/swarm/swarm_notif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
)

func TestNotifications(t *testing.T) {
t.Parallel()

ctx := context.Background()
swarms := makeSwarms(ctx, t, 5)
defer func() {
Expand Down Expand Up @@ -44,24 +42,30 @@ func TestNotifications(t *testing.T) {
continue
}

cos := s.ConnectionsToPeer(s2.LocalPeer())
func() {
for i := 0; i < len(cos); i++ {
var c inet.Conn
select {
case c = <-n.connected:
case <-time.After(timeout):
t.Fatal("timeout")
}
for _, c2 := range cos {
if c == c2 {
t.Log("got notif for conn", c)
return
}
var actual []inet.Conn
for len(s.ConnectionsToPeer(s2.LocalPeer())) != len(actual) {
select {
case c := <-n.connected:
actual = append(actual, c)
case <-time.After(timeout):
t.Fatal("timeout")
}
}

expect := s.ConnectionsToPeer(s2.LocalPeer())
for _, c1 := range actual {
found := false
for _, c2 := range expect {
if c1 == c2 {
found = true
break
}
t.Error("connection not found", c)
}
}()
if !found {
t.Error("connection not found")
}
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion p2p/net/swarm/swarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,6 @@ func TestFilterBounds(t *testing.T) {
case <-time.After(time.Second):
t.Fatal("should have gotten connection")
case <-conns:
fmt.Println("got connect")
t.Log("got connect")
}
}

0 comments on commit 59d6a9a

Please sign in to comment.