Commit 8e3cde2f authored by acud's avatar acud Committed by GitHub

fix: flaky test (#2359)

parent 23cee426
......@@ -32,7 +32,7 @@ require (
github.com/libp2p/go-libp2p-discovery v0.5.1 // indirect
github.com/libp2p/go-libp2p-peerstore v0.2.7
github.com/libp2p/go-libp2p-quic-transport v0.10.0
github.com/libp2p/go-libp2p-swarm v0.5.0 // indirect
github.com/libp2p/go-libp2p-swarm v0.5.0
github.com/libp2p/go-libp2p-transport-upgrader v0.4.2
github.com/libp2p/go-tcp-transport v0.2.3
github.com/libp2p/go-ws-transport v0.4.0
......
......@@ -608,15 +608,33 @@ func TestTopologyAnnounce(t *testing.T) {
expectPeers(t, s3, overlay1)
expectPeersEventually(t, s1, overlay3)
called := false
mtx.Lock()
if !announceCalled {
for i := 0; i < 20; i++ {
mtx.Lock()
called = announceCalled
mtx.Unlock()
if called {
break
}
time.Sleep(50 * time.Millisecond)
}
if !called {
t.Error("expected announce to be called")
}
for i := 0; i < 10; i++ {
mtx.Lock()
called = announceToCalled
mtx.Unlock()
if called {
break
}
time.Sleep(50 * time.Millisecond)
}
if announceToCalled {
t.Error("announceTo called but should not")
}
mtx.Unlock()
// check address book entries are there
checkAddressbook(t, ab3, overlay1, addr)
......@@ -630,11 +648,19 @@ func TestTopologyAnnounce(t *testing.T) {
expectPeers(t, s2, overlay1)
expectPeersEventually(t, s1, overlay2, overlay3)
mtx.Lock()
if !announceToCalled {
for i := 0; i < 20; i++ {
mtx.Lock()
called = announceToCalled
mtx.Unlock()
if called {
break
}
time.Sleep(50 * time.Millisecond)
}
if !called {
t.Error("expected announceTo to be called")
}
mtx.Unlock()
}
func TestTopologyOverSaturated(t *testing.T) {
......
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