Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added goroutine leak detector to TestNewHost #7

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
8 changes: 7 additions & 1 deletion host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"),
Expand All @@ -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)
Expand Down