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:
sukun
2024-08-15 18:18:35 +05:30
committed by GitHub
parent e276a6efad
commit 8a11b7c8e4
4 changed files with 32 additions and 30 deletions

View File

@@ -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) {