From 0966ab8776c7ecbae448fab44c2e8b35ca39a0e4 Mon Sep 17 00:00:00 2001 From: gammazero Date: Fri, 6 Oct 2023 16:17:21 -0700 Subject: [PATCH] Add goroutine leak detection to unit test Check that shutdown works correctly by checking for any goroutines that are still running. --- go.mod | 1 + go.sum | 2 ++ integration/singularity/store_test.go | 12 ++++++++++++ 3 files changed, 15 insertions(+) diff --git a/go.mod b/go.mod index ad230e0..27e6d68 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/ipfs/go-log/v2 v2.5.1 github.com/stretchr/testify v1.8.4 github.com/urfave/cli/v2 v2.25.7 + go.uber.org/goleak v1.2.0 ) require ( diff --git a/go.sum b/go.sum index 818583f..0ba4538 100644 --- a/go.sum +++ b/go.sum @@ -669,6 +669,7 @@ go.uber.org/fx v1.20.0 h1:ZMC/pnRvhsthOZh9MZjMq5U8Or3mA9zBSPaLnzs3ihQ= go.uber.org/fx v1.20.0/go.mod h1:qCUj0btiR3/JnanEr1TYEePfSw6o/4qYJscgvzQ5Ub0= go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= +go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= @@ -707,6 +708,7 @@ golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTk golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= diff --git a/integration/singularity/store_test.go b/integration/singularity/store_test.go index c69ab63..30b19ec 100644 --- a/integration/singularity/store_test.go +++ b/integration/singularity/store_test.go @@ -13,9 +13,21 @@ import ( singularityclient "github.com/data-preservation-programs/singularity/client/swagger/http" "github.com/filecoin-project/motion/integration/singularity" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func checkGoLeaks(t *testing.T) { + // Ignore goroutines that are already running. + ignoreCurrent := goleak.IgnoreCurrent() + // Check if new goroutines are still running at end of test. + t.Cleanup(func() { + goleak.VerifyNone(t, ignoreCurrent) + }) +} + func TestStorePut(t *testing.T) { + checkGoLeaks(t) + testServer := httptest.NewServer(http.HandlerFunc(testHandler)) t.Cleanup(func() { testServer.Close()