mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 01:52:26 +08:00
fix swarm notif tests
they were failing intermittently License: MIT Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
This commit is contained in:
@ -11,8 +11,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestNotifications(t *testing.T) {
|
func TestNotifications(t *testing.T) {
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
swarms := makeSwarms(ctx, t, 5)
|
swarms := makeSwarms(ctx, t, 5)
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -44,24 +42,30 @@ func TestNotifications(t *testing.T) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
cos := s.ConnectionsToPeer(s2.LocalPeer())
|
var actual []inet.Conn
|
||||||
func() {
|
for len(s.ConnectionsToPeer(s2.LocalPeer())) != len(actual) {
|
||||||
for i := 0; i < len(cos); i++ {
|
select {
|
||||||
var c inet.Conn
|
case c := <-n.connected:
|
||||||
select {
|
actual = append(actual, c)
|
||||||
case c = <-n.connected:
|
case <-time.After(timeout):
|
||||||
case <-time.After(timeout):
|
t.Fatal("timeout")
|
||||||
t.Fatal("timeout")
|
|
||||||
}
|
|
||||||
for _, c2 := range cos {
|
|
||||||
if c == c2 {
|
|
||||||
t.Log("got notif for conn", c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
t.Error("connection not found", c)
|
|
||||||
}
|
}
|
||||||
}()
|
}
|
||||||
|
|
||||||
|
expect := s.ConnectionsToPeer(s2.LocalPeer())
|
||||||
|
for _, c1 := range actual {
|
||||||
|
found := false
|
||||||
|
for _, c2 := range expect {
|
||||||
|
if c1 == c2 {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
t.Error("connection not found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,6 +325,6 @@ func TestFilterBounds(t *testing.T) {
|
|||||||
case <-time.After(time.Second):
|
case <-time.After(time.Second):
|
||||||
t.Fatal("should have gotten connection")
|
t.Fatal("should have gotten connection")
|
||||||
case <-conns:
|
case <-conns:
|
||||||
fmt.Println("got connect")
|
t.Log("got connect")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user