Skip to content

Commit

Permalink
fix flaky TestAutoRelay test
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Jan 10, 2022
1 parent c126f37 commit 1beb093
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions p2p/host/autorelay/autorelay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ type mockRoutingTable struct {
peers map[peer.ID]peer.AddrInfo
}

func (t *mockRoutingTable) NumPeers() int {
t.mx.Lock()
defer t.mx.Unlock()
return len(t.peers)
}

type mockRouting struct {
h host.Host
tab *mockRoutingTable
Expand Down Expand Up @@ -175,6 +181,7 @@ func testAutoRelay(t *testing.T, useRelayv2 bool) {
require.NoError(t, err)
relayDiscovery := discovery.NewRoutingDiscovery(relayRouting)
autorelay.Advertise(context.Background(), relayDiscovery)
require.Eventually(t, func() bool { return mtab.NumPeers() > 0 }, time.Second, 10*time.Millisecond)

// the client hosts
h1, err := libp2p.New(libp2p.EnableRelay())
Expand Down

0 comments on commit 1beb093

Please sign in to comment.