Skip to content

Commit 7b88776

Browse files
authored
chore(testutil): add testutil.GoleakOptions (#16070)
- Adds `testutil.GoleakOptions` and consolidates existing options to this location - Pre-emptively adds required ignore for this Dependabot PR to pass CI #16066
1 parent 106b1cd commit 7b88776

36 files changed

+60
-43
lines changed

agent/agent_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import (
5858
)
5959

6060
func TestMain(m *testing.M) {
61-
goleak.VerifyTestMain(m)
61+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
6262
}
6363

6464
// NOTE: These tests only work when your default shell is bash for some reason.

agent/agentscripts/agentscripts_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
func TestMain(m *testing.M) {
27-
goleak.VerifyTestMain(m)
27+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
2828
}
2929

3030
func TestExecuteBasic(t *testing.T) {

agent/agentssh/agentssh_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
)
3030

3131
func TestMain(m *testing.M) {
32-
goleak.VerifyTestMain(m)
32+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
3333
}
3434

3535
func TestNewServer_ServeClient(t *testing.T) {

cli/clitest/clitest_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import (
88
"github.com/coder/coder/v2/cli/clitest"
99
"github.com/coder/coder/v2/coderd/coderdtest"
1010
"github.com/coder/coder/v2/pty/ptytest"
11+
"github.com/coder/coder/v2/testutil"
1112
)
1213

1314
func TestMain(m *testing.M) {
14-
goleak.VerifyTestMain(m)
15+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
1516
}
1617

1718
func TestCli(t *testing.T) {

cli/root_internal_test.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/coder/coder/v2/cli/cliui"
2020
"github.com/coder/coder/v2/cli/telemetry"
2121
"github.com/coder/coder/v2/codersdk"
22+
"github.com/coder/coder/v2/testutil"
2223
"github.com/coder/pretty"
2324
"github.com/coder/serpent"
2425
)
@@ -29,15 +30,7 @@ func TestMain(m *testing.M) {
2930
// See: https://github.com/coder/coder/issues/8954
3031
os.Exit(m.Run())
3132
}
32-
goleak.VerifyTestMain(m,
33-
// The lumberjack library is used by by agent and seems to leave
34-
// goroutines after Close(), fails TestGitSSH tests.
35-
// https://github.com/natefinch/lumberjack/pull/100
36-
goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).millRun"),
37-
goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).mill.func1"),
38-
// The pq library appears to leave around a goroutine after Close().
39-
goleak.IgnoreTopFunction("github.com/lib/pq.NewDialListener"),
40-
)
33+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
4134
}
4235

4336
func Test_formatExamples(t *testing.T) {

coderd/autobuild/lifecycle_executor_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1256,5 +1256,5 @@ func mustWorkspaceParameters(t *testing.T, client *codersdk.Client, workspaceID
12561256
}
12571257

12581258
func TestMain(m *testing.M) {
1259-
goleak.VerifyTestMain(m)
1259+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
12601260
}

coderd/autobuild/notify/notifier_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,5 @@ func durations(ds ...time.Duration) []time.Duration {
122122
}
123123

124124
func TestMain(m *testing.M) {
125-
goleak.VerifyTestMain(m)
125+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
126126
}

coderd/coderd_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
var updateGoldenFiles = flag.Bool("update", false, "Update golden files")
4040

4141
func TestMain(m *testing.M) {
42-
goleak.VerifyTestMain(m)
42+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
4343
}
4444

4545
func TestBuildInfo(t *testing.T) {

coderd/coderdtest/coderdtest_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import (
66
"go.uber.org/goleak"
77

88
"github.com/coder/coder/v2/coderd/coderdtest"
9+
"github.com/coder/coder/v2/testutil"
910
)
1011

1112
func TestMain(m *testing.M) {
12-
goleak.VerifyTestMain(m)
13+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
1314
}
1415

1516
func TestNew(t *testing.T) {

coderd/cryptokeys/cache_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
func TestMain(m *testing.M) {
21-
goleak.VerifyTestMain(m)
21+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
2222
}
2323

2424
func TestCryptoKeyCache(t *testing.T) {

coderd/database/dbpurge/dbpurge_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
)
3535

3636
func TestMain(m *testing.M) {
37-
goleak.VerifyTestMain(m)
37+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
3838
}
3939

4040
// Ensures no goroutines leak.

coderd/database/dbrollup/dbrollup_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
func TestMain(m *testing.M) {
26-
goleak.VerifyTestMain(m)
26+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
2727
}
2828

2929
func TestRollup_Close(t *testing.T) {

coderd/database/dbtestutil/postgres_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import (
1212

1313
"github.com/coder/coder/v2/coderd/database/dbtestutil"
1414
"github.com/coder/coder/v2/coderd/database/migrations"
15+
"github.com/coder/coder/v2/testutil"
1516
)
1617

1718
func TestMain(m *testing.M) {
18-
goleak.VerifyTestMain(m)
19+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
1920
}
2021

2122
func TestOpen(t *testing.T) {

coderd/database/migrations/migrate_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
func TestMain(m *testing.M) {
31-
goleak.VerifyTestMain(m)
31+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
3232
}
3333

3434
func TestMigrate(t *testing.T) {

coderd/notifications/dispatch/smtp_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
func TestMain(m *testing.M) {
29-
goleak.VerifyTestMain(m)
29+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
3030
}
3131

3232
func TestSMTP(t *testing.T) {

coderd/notifications/notifications_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import (
5656
var updateGoldenFiles = flag.Bool("update", false, "Update golden files")
5757

5858
func TestMain(m *testing.M) {
59-
goleak.VerifyTestMain(m)
59+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
6060
}
6161

6262
// TestBasicNotificationRoundtrip enqueues a message to the store, waits for it to be acquired by a notifier,

coderd/provisionerdserver/acquirer_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
func TestMain(m *testing.M) {
31-
goleak.VerifyTestMain(m)
31+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
3232
}
3333

3434
// TestAcquirer_Store tests that a database.Store is accepted as a provisionerdserver.AcquirerStore

coderd/telemetry/telemetry_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
func TestMain(m *testing.M) {
30-
goleak.VerifyTestMain(m)
30+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
3131
}
3232

3333
func TestTelemetry(t *testing.T) {

coderd/unhanger/detector_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
func TestMain(m *testing.M) {
31-
goleak.VerifyTestMain(m)
31+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
3232
}
3333

3434
func TestDetectorNoJobs(t *testing.T) {

coderd/updatecheck/updatecheck_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,5 @@ func TestChecker_Latest(t *testing.T) {
154154
}
155155

156156
func TestMain(m *testing.M) {
157-
goleak.VerifyTestMain(m)
157+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
158158
}

coderd/workspacestats/tracker_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,5 +219,5 @@ func TestTracker_MultipleInstances(t *testing.T) {
219219
}
220220

221221
func TestMain(m *testing.M) {
222-
goleak.VerifyTestMain(m)
222+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
223223
}

enterprise/coderd/coderd_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import (
5555
)
5656

5757
func TestMain(m *testing.M) {
58-
goleak.VerifyTestMain(m)
58+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
5959
}
6060

6161
func TestEntitlements(t *testing.T) {

enterprise/derpmesh/derpmesh_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
func TestMain(m *testing.M) {
26-
goleak.VerifyTestMain(m)
26+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
2727
}
2828

2929
func TestDERPMesh(t *testing.T) {

enterprise/provisionerd/remoteprovisioners_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
)
2121

2222
func TestMain(m *testing.M) {
23-
goleak.VerifyTestMain(m)
23+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
2424
}
2525

2626
func TestRemoteConnector_Mainline(t *testing.T) {

enterprise/replicasync/replicasync_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
)
2626

2727
func TestMain(m *testing.M) {
28-
goleak.VerifyTestMain(m)
28+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
2929
}
3030

3131
func TestReplica(t *testing.T) {

enterprise/tailnet/pgcoord_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
func TestMain(m *testing.M) {
34-
goleak.VerifyTestMain(m)
34+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
3535
}
3636

3737
func TestPGCoordinatorSingle_ClientWithoutAgent(t *testing.T) {

provisionerd/provisionerd_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
)
3131

3232
func TestMain(m *testing.M) {
33-
goleak.VerifyTestMain(m)
33+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
3434
}
3535

3636
func closedWithin(c chan struct{}, d time.Duration) func() bool {

provisionersdk/serve_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
func TestMain(m *testing.M) {
20-
goleak.VerifyTestMain(m)
20+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
2121
}
2222

2323
func TestProvisionerSDK(t *testing.T) {

pty/start_other_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ import (
1515

1616
"github.com/coder/coder/v2/pty"
1717
"github.com/coder/coder/v2/pty/ptytest"
18+
"github.com/coder/coder/v2/testutil"
1819
)
1920

2021
func TestMain(m *testing.M) {
21-
goleak.VerifyTestMain(m)
22+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
2223
}
2324

2425
func TestStart(t *testing.T) {

pty/start_windows_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import (
1111

1212
"github.com/coder/coder/v2/pty"
1313
"github.com/coder/coder/v2/pty/ptytest"
14+
"github.com/coder/coder/v2/testutil"
1415
"github.com/stretchr/testify/assert"
1516
"github.com/stretchr/testify/require"
1617
"go.uber.org/goleak"
1718
"golang.org/x/xerrors"
1819
)
1920

2021
func TestMain(m *testing.M) {
21-
goleak.VerifyTestMain(m)
22+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
2223
}
2324

2425
func TestStart(t *testing.T) {

support/support_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
)
3131

3232
func TestMain(m *testing.M) {
33-
goleak.VerifyTestMain(m)
33+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
3434
}
3535

3636
func TestRun(t *testing.T) {

tailnet/conn_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
func TestMain(m *testing.M) {
22-
goleak.VerifyTestMain(m)
22+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
2323
}
2424

2525
func TestTailnet(t *testing.T) {

tailnet/tailnettest/tailnettest_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import (
66
"go.uber.org/goleak"
77

88
"github.com/coder/coder/v2/tailnet/tailnettest"
9+
"github.com/coder/coder/v2/testutil"
910
)
1011

1112
func TestMain(m *testing.M) {
12-
goleak.VerifyTestMain(m)
13+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
1314
}
1415

1516
func TestRunDERPAndSTUN(t *testing.T) {

testutil/eventually_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func TestMain(m *testing.M) {
14-
goleak.VerifyTestMain(m)
14+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
1515
}
1616

1717
func TestEventually(t *testing.T) {

testutil/goleak.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package testutil
2+
3+
import "go.uber.org/goleak"
4+
5+
// GoleakOptions is a common list of options to pass to goleak. This is useful if there is a known
6+
// leaky function we want to exclude from goleak.
7+
var GoleakOptions []goleak.Option = []goleak.Option{
8+
// seelog (indirect dependency of dd-trace-go) has a known goroutine leak (https://github.com/cihub/seelog/issues/182)
9+
// When https://github.com/DataDog/dd-trace-go/issues/2987 is resolved, this can be removed.
10+
goleak.IgnoreAnyFunction("github.com/cihub/seelog.(*asyncLoopLogger).processQueue"),
11+
// The lumberjack library is used by by agent and seems to leave
12+
// goroutines after Close(), fails TestGitSSH tests.
13+
// https://github.com/natefinch/lumberjack/pull/100
14+
goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).millRun"),
15+
goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).mill.func1"),
16+
// The pq library appears to leave around a goroutine after Close().
17+
goleak.IgnoreTopFunction("github.com/lib/pq.NewDialListener"),
18+
}

vpn/speaker_internal_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
func TestMain(m *testing.M) {
22-
goleak.VerifyTestMain(m)
22+
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
2323
}
2424

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

0 commit comments

Comments
 (0)