Commit 57e6cb40 authored by Jeromy's avatar Jeromy
Browse files

fix race condition in notifications test



License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent 1879bb06
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
ma "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr" ma "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context" context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
inet "github.com/ipfs/go-ipfs/p2p/net" inet "github.com/ipfs/go-ipfs/p2p/net"
peer "github.com/ipfs/go-ipfs/p2p/peer"
) )
func TestNotifications(t *testing.T) { func TestNotifications(t *testing.T) {
...@@ -42,31 +43,29 @@ func TestNotifications(t *testing.T) { ...@@ -42,31 +43,29 @@ func TestNotifications(t *testing.T) {
// test everyone got the correct connection opened calls // test everyone got the correct connection opened calls
for i, s := range nets { for i, s := range nets {
n := notifiees[i] n := notifiees[i]
for _, s2 := range nets { notifs := make(map[peer.ID]inet.Conn)
var actual []inet.Conn for j := 0; j < len(nets)-1; j++ {
for len(s.ConnsToPeer(s2.LocalPeer())) != len(actual) { select {
select { case c := <-n.connected:
case c := <-n.connected: _, ok := notifs[c.RemotePeer()]
actual = append(actual, c) if ok {
case <-time.After(timeout): t.Fatal("shouldnt have received more than one connection per peer")
t.Fatal("timeout")
} }
notifs[c.RemotePeer()] = c
case <-time.After(timeout):
t.Fatal("timeout")
} }
}
expect := s.ConnsToPeer(s2.LocalPeer()) for p, con := range notifs {
for _, c1 := range actual { expect := s.ConnsToPeer(p)
found := false if len(expect) != 1 {
for _, c2 := range expect { t.Fatal("got more than one connection, not supposed to happen")
if c1 == c2 {
found = true
break
}
}
if !found {
t.Error("connection not found", c1, len(expect), len(actual))
}
} }
if expect[0] != con {
t.Fatal("got different connection than we expected")
}
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment