diff --git a/go.mod b/go.mod index cc72cd5..4c18581 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/athanorlabs/go-p2p-net go 1.19 require ( + github.com/fortytw2/leaktest v1.3.0 github.com/ipfs/go-ds-badger2 v0.1.3 github.com/ipfs/go-log v1.0.5 github.com/libp2p/go-libp2p v0.26.2 diff --git a/go.sum b/go.sum index 06ac173..cc66eba 100644 --- a/go.sum +++ b/go.sum @@ -78,6 +78,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ= github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= +github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= +github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk= github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= diff --git a/host_test.go b/host_test.go index 1b51adc..8ec68d7 100644 --- a/host_test.go +++ b/host_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/fortytw2/leaktest" logging "github.com/ipfs/go-log" "github.com/libp2p/go-libp2p/core/peer" "github.com/stretchr/testify/require" @@ -20,8 +21,12 @@ func init() { func basicTestConfig(t *testing.T, namespaces []string) *Config { // t.TempDir() is unique on every call. Don't reuse this config with multiple hosts. tmpDir := t.TempDir() + + ctx, cancel := context.WithCancel(context.Background()) + t.Cleanup(cancel) + return &Config{ - Ctx: context.Background(), + Ctx: ctx, DataDir: tmpDir, Port: 0, // OS randomized libp2p port KeyFile: path.Join(tmpDir, "node.key"), @@ -44,6 +49,7 @@ func newHost(t *testing.T, cfg *Config) *Host { } func TestNewHost(t *testing.T) { + t.Cleanup(leaktest.Check(t)) h := newHost(t, basicTestConfig(t, []string{""})) err := h.Start() require.NoError(t, err)