mirror of
https://github.com/libp2p/go-libp2p.git
synced 2025-10-22 07:40:31 +08:00
basic_host: close swarm on Close (#2916)
Using the `BasicHost` constructor transfers the ownership of the swarm. This is similar to how using `libp2p.New` transfers the ownership of user provided config options like `ResourceManager`, all of which are closed on `host.Close`
This commit is contained in:
@@ -83,7 +83,15 @@ func TestMultipleClose(t *testing.T) {
|
||||
|
||||
require.NoError(t, h.Close())
|
||||
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)
|
||||
_, err = h.NewStream(context.Background(), h2.ID())
|
||||
require.Error(t, err)
|
||||
require.Empty(t, h.Addrs())
|
||||
require.Empty(t, h.AllAddrs())
|
||||
}
|
||||
|
||||
func TestSignedPeerRecordWithNoListenAddrs(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user