Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ipfs/kubo
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8c0ca5e376e4
Choose a base ref
...
head repository: ipfs/kubo
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ebfdb3a4d8dc
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Jul 22, 2015

  1. fix race condition in notifications test

    License: MIT
    Signed-off-by: Jeromy <jeromyj@gmail.com>
    whyrusleeping committed Jul 22, 2015
    Copy the full SHA
    b60f494 View commit details
  2. fix same test in swarm

    License: MIT
    Signed-off-by: Jeromy <jeromyj@gmail.com>
    whyrusleeping committed Jul 22, 2015

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    47cd70f View commit details

Commits on Jul 23, 2015

  1. Merge pull request #1501 from ipfs/fix/notif-test

    fix race condition in notifications test
    jbenet committed Jul 23, 2015
    Copy the full SHA
    ebfdb3a View commit details
Showing with 43 additions and 21 deletions.
  1. +23 −10 p2p/net/mock/mock_notif_test.go
  2. +20 −11 p2p/net/swarm/swarm_notif_test.go
33 changes: 23 additions & 10 deletions p2p/net/mock/mock_notif_test.go
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import (
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"
inet "github.com/ipfs/go-ipfs/p2p/net"
peer "github.com/ipfs/go-ipfs/p2p/peer"
)

func TestNotifications(t *testing.T) {
@@ -42,31 +43,43 @@ func TestNotifications(t *testing.T) {
// test everyone got the correct connection opened calls
for i, s := range nets {
n := notifiees[i]
for _, s2 := range nets {
var actual []inet.Conn
for len(s.ConnsToPeer(s2.LocalPeer())) != len(actual) {
notifs := make(map[peer.ID][]inet.Conn)
for j, s2 := range nets {
if i == j {
continue
}

// this feels a little sketchy, but its probably okay
for len(s.ConnsToPeer(s2.LocalPeer())) != len(notifs[s2.LocalPeer()]) {
select {
case c := <-n.connected:
actual = append(actual, c)
nfp := notifs[c.RemotePeer()]
notifs[c.RemotePeer()] = append(nfp, c)
case <-time.After(timeout):
t.Fatal("timeout")
}
}
}

for p, cons := range notifs {
expect := s.ConnsToPeer(p)
if len(expect) != len(cons) {
t.Fatal("got different number of connections")
}

expect := s.ConnsToPeer(s2.LocalPeer())
for _, c1 := range actual {
found := false
for _, c := range cons {
var found bool
for _, c2 := range expect {
if c1 == c2 {
if c == c2 {
found = true
break
}
}

if !found {
t.Error("connection not found", c1, len(expect), len(actual))
t.Fatal("connection not found!")
}
}

}
}

31 changes: 20 additions & 11 deletions p2p/net/swarm/swarm_notif_test.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import (
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"

inet "github.com/ipfs/go-ipfs/p2p/net"
peer "github.com/ipfs/go-ipfs/p2p/peer"
)

func TestNotifications(t *testing.T) {
@@ -37,35 +38,43 @@ func TestNotifications(t *testing.T) {
// test everyone got the correct connection opened calls
for i, s := range swarms {
n := notifiees[i]
for _, s2 := range swarms {
if s == s2 {
notifs := make(map[peer.ID][]inet.Conn)
for j, s2 := range swarms {
if i == j {
continue
}

var actual []inet.Conn
for len(s.ConnectionsToPeer(s2.LocalPeer())) != len(actual) {
// this feels a little sketchy, but its probably okay
for len(s.ConnectionsToPeer(s2.LocalPeer())) != len(notifs[s2.LocalPeer()]) {
select {
case c := <-n.connected:
actual = append(actual, c)
nfp := notifs[c.RemotePeer()]
notifs[c.RemotePeer()] = append(nfp, c)
case <-time.After(timeout):
t.Fatal("timeout")
}
}
}

for p, cons := range notifs {
expect := s.ConnectionsToPeer(p)
if len(expect) != len(cons) {
t.Fatal("got different number of connections")
}

expect := s.ConnectionsToPeer(s2.LocalPeer())
for _, c1 := range actual {
found := false
for _, c := range cons {
var found bool
for _, c2 := range expect {
if c1 == c2 {
if c == c2 {
found = true
break
}
}

if !found {
t.Error("connection not found")
t.Fatal("connection not found!")
}
}

}
}