Skip to content

chore(testutil): add testutil.GoleakOptions #16070

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

Merged
merged 1 commit into from
Jan 8, 2025
Merged
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
chore(testutil): add testutil.GoleakOptions
  • Loading branch information
johnstcn committed Jan 8, 2025
commit 8088f20a3aedee74d3b7fdf24fbc58edb7c4f6ec
2 changes: 1 addition & 1 deletion agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

// NOTE: These tests only work when your default shell is bash for some reason.
Expand Down
2 changes: 1 addition & 1 deletion agent/agentscripts/agentscripts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestExecuteBasic(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion agent/agentssh/agentssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestNewServer_ServeClient(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion cli/clitest/clitest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"github.com/coder/coder/v2/cli/clitest"
"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/pty/ptytest"
"github.com/coder/coder/v2/testutil"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestCli(t *testing.T) {
Expand Down
11 changes: 2 additions & 9 deletions cli/root_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/cli/telemetry"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/testutil"
"github.com/coder/pretty"
"github.com/coder/serpent"
)
Expand All @@ -29,15 +30,7 @@ func TestMain(m *testing.M) {
// See: https://github.com/coder/coder/issues/8954
os.Exit(m.Run())
}
goleak.VerifyTestMain(m,
// The lumberjack library is used by by agent and seems to leave
// goroutines after Close(), fails TestGitSSH tests.
// https://github.com/natefinch/lumberjack/pull/100
goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).millRun"),
goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).mill.func1"),
// The pq library appears to leave around a goroutine after Close().
goleak.IgnoreTopFunction("github.com/lib/pq.NewDialListener"),
)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func Test_formatExamples(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion coderd/autobuild/lifecycle_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1256,5 +1256,5 @@ func mustWorkspaceParameters(t *testing.T, client *codersdk.Client, workspaceID
}

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
2 changes: 1 addition & 1 deletion coderd/autobuild/notify/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@ func durations(ds ...time.Duration) []time.Duration {
}

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
2 changes: 1 addition & 1 deletion coderd/coderd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
var updateGoldenFiles = flag.Bool("update", false, "Update golden files")

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestBuildInfo(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion coderd/coderdtest/coderdtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"go.uber.org/goleak"

"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/testutil"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestNew(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion coderd/cryptokeys/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestCryptoKeyCache(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion coderd/database/dbpurge/dbpurge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

// Ensures no goroutines leak.
Expand Down
2 changes: 1 addition & 1 deletion coderd/database/dbrollup/dbrollup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestRollup_Close(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion coderd/database/dbtestutil/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (

"github.com/coder/coder/v2/coderd/database/dbtestutil"
"github.com/coder/coder/v2/coderd/database/migrations"
"github.com/coder/coder/v2/testutil"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestOpen(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion coderd/database/migrations/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestMigrate(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion coderd/notifications/dispatch/smtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestSMTP(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion coderd/notifications/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import (
var updateGoldenFiles = flag.Bool("update", false, "Update golden files")

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

// TestBasicNotificationRoundtrip enqueues a message to the store, waits for it to be acquired by a notifier,
Expand Down
2 changes: 1 addition & 1 deletion coderd/provisionerdserver/acquirer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

// TestAcquirer_Store tests that a database.Store is accepted as a provisionerdserver.AcquirerStore
Expand Down
2 changes: 1 addition & 1 deletion coderd/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestTelemetry(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion coderd/unhanger/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestDetectorNoJobs(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion coderd/updatecheck/updatecheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,5 @@ func TestChecker_Latest(t *testing.T) {
}

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
2 changes: 1 addition & 1 deletion coderd/workspacestats/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,5 @@ func TestTracker_MultipleInstances(t *testing.T) {
}

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
2 changes: 1 addition & 1 deletion enterprise/coderd/coderd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestEntitlements(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion enterprise/derpmesh/derpmesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestDERPMesh(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion enterprise/provisionerd/remoteprovisioners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestRemoteConnector_Mainline(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion enterprise/replicasync/replicasync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestReplica(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion enterprise/tailnet/pgcoord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestPGCoordinatorSingle_ClientWithoutAgent(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion provisionerd/provisionerd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func closedWithin(c chan struct{}, d time.Duration) func() bool {
Expand Down
2 changes: 1 addition & 1 deletion provisionersdk/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestProvisionerSDK(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pty/start_other_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import (

"github.com/coder/coder/v2/pty"
"github.com/coder/coder/v2/pty/ptytest"
"github.com/coder/coder/v2/testutil"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestStart(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pty/start_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (

"github.com/coder/coder/v2/pty"
"github.com/coder/coder/v2/pty/ptytest"
"github.com/coder/coder/v2/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
"golang.org/x/xerrors"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestStart(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion support/support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestRun(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tailnet/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestTailnet(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion tailnet/tailnettest/tailnettest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"go.uber.org/goleak"

"github.com/coder/coder/v2/tailnet/tailnettest"
"github.com/coder/coder/v2/testutil"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestRunDERPAndSTUN(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion testutil/eventually_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

func TestEventually(t *testing.T) {
Expand Down
18 changes: 18 additions & 0 deletions testutil/goleak.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package testutil

import "go.uber.org/goleak"

// GoleakOptions is a common list of options to pass to goleak. This is useful if there is a known
// leaky function we want to exclude from goleak.
var GoleakOptions []goleak.Option = []goleak.Option{
// seelog (indirect dependency of dd-trace-go) has a known goroutine leak (https://github.com/cihub/seelog/issues/182)
// When https://github.com/DataDog/dd-trace-go/issues/2987 is resolved, this can be removed.
goleak.IgnoreAnyFunction("github.com/cihub/seelog.(*asyncLoopLogger).processQueue"),
// The lumberjack library is used by by agent and seems to leave
// goroutines after Close(), fails TestGitSSH tests.
// https://github.com/natefinch/lumberjack/pull/100
goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).millRun"),
goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).mill.func1"),
// The pq library appears to leave around a goroutine after Close().
goleak.IgnoreTopFunction("github.com/lib/pq.NewDialListener"),
}
2 changes: 1 addition & 1 deletion vpn/speaker_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

// TestSpeaker_RawPeer tests the speaker with a peer that we simulate by directly making reads and
Expand Down
Loading