diff --git a/libp2p_test.go b/libp2p_test.go index 676af7696e..afa6c7a6ba 100644 --- a/libp2p_test.go +++ b/libp2p_test.go @@ -13,7 +13,6 @@ import ( "github.com/libp2p/go-libp2p/core/connmgr" "github.com/libp2p/go-libp2p/core/crypto" - "github.com/libp2p/go-libp2p/core/event" "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" @@ -429,24 +428,15 @@ func TestMain(m *testing.M) { } func TestDialCircuitAddrWithWrappedResourceManager(t *testing.T) { - relay, err := New(EnableRelayService()) + relay, err := New(EnableRelayService(), ForceReachabilityPublic()) require.NoError(t, err) defer relay.Close() - // Fake that the relay is publicly reachable - emitterForRelay, err := relay.EventBus().Emitter(&event.EvtLocalReachabilityChanged{}) - require.NoError(t, err) - defer emitterForRelay.Close() - emitterForRelay.Emit(event.EvtLocalReachabilityChanged{Reachability: network.ReachabilityPublic}) - - peerBehindRelay, err := New(EnableAutoRelayWithStaticRelays([]peer.AddrInfo{{ID: relay.ID(), Addrs: relay.Addrs()}})) + peerBehindRelay, err := New( + EnableAutoRelayWithStaticRelays([]peer.AddrInfo{{ID: relay.ID(), Addrs: relay.Addrs()}}), + ForceReachabilityPrivate()) require.NoError(t, err) defer peerBehindRelay.Close() - // Emit an event to tell this peer it is private - emitterForPeerBehindRelay, err := peerBehindRelay.EventBus().Emitter(&event.EvtLocalReachabilityChanged{}) - require.NoError(t, err) - defer emitterForPeerBehindRelay.Close() - emitterForPeerBehindRelay.Emit(event.EvtLocalReachabilityChanged{Reachability: network.ReachabilityPrivate}) // Use a wrapped resource manager to test that the circuit dialing works // with it. Look at the PR introducing this test for context @@ -467,10 +457,12 @@ func TestDialCircuitAddrWithWrappedResourceManager(t *testing.T) { ) require.NoError(t, err) - ctx, cancel := context.WithCancel(context.Background()) - res := <-ping.Ping(ctx, h, peerBehindRelay.ID()) - require.NoError(t, res.Error) - defer cancel() + require.Eventually(t, func() bool { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + res := <-ping.Ping(ctx, h, peerBehindRelay.ID()) + return res.Error == nil + }, 5*time.Second, 50*time.Millisecond) } func TestHostAddrsFactoryAddsCerthashes(t *testing.T) { diff --git a/p2p/host/basic/basic_host_test.go b/p2p/host/basic/basic_host_test.go index ba3eac0cd5..9014e1b4df 100644 --- a/p2p/host/basic/basic_host_test.go +++ b/p2p/host/basic/basic_host_test.go @@ -84,6 +84,7 @@ func TestMultipleClose(t *testing.T) { require.NoError(t, h.Close()) require.NoError(t, h.Close()) h2, err := NewHost(swarmt.GenSwarm(t), nil) + require.NoError(t, err) defer h2.Close() require.Error(t, h.Connect(context.Background(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})) h.Network().Peerstore().AddAddrs(h2.ID(), h2.Addrs(), peerstore.PermanentAddrTTL)