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
https://github.com/coder/coder/pull/16066
This commit is contained in:
Cian Johnston
2025-01-08 15:38:37 +00:00
committed by GitHub
parent 106b1cd3bc
commit 7b88776403
36 changed files with 60 additions and 43 deletions

View File

@ -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.

View File

@ -24,7 +24,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestExecuteBasic(t *testing.T) {

View File

@ -29,7 +29,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestNewServer_ServeClient(t *testing.T) {

View File

@ -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) {

View File

@ -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"
)
@ -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) {

View File

@ -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...)
}

View File

@ -122,5 +122,5 @@ func durations(ds ...time.Duration) []time.Duration {
}
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

View File

@ -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) {

View File

@ -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) {

View File

@ -18,7 +18,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestCryptoKeyCache(t *testing.T) {

View File

@ -34,7 +34,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
// Ensures no goroutines leak.

View File

@ -23,7 +23,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestRollup_Close(t *testing.T) {

View File

@ -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) {

View File

@ -28,7 +28,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestMigrate(t *testing.T) {

View File

@ -26,7 +26,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestSMTP(t *testing.T) {

View File

@ -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,

View File

@ -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

View File

@ -27,7 +27,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestTelemetry(t *testing.T) {

View File

@ -28,7 +28,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestDetectorNoJobs(t *testing.T) {

View File

@ -154,5 +154,5 @@ func TestChecker_Latest(t *testing.T) {
}
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

View File

@ -219,5 +219,5 @@ func TestTracker_MultipleInstances(t *testing.T) {
}
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}

View File

@ -55,7 +55,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestEntitlements(t *testing.T) {

View File

@ -23,7 +23,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestDERPMesh(t *testing.T) {

View File

@ -20,7 +20,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestRemoteConnector_Mainline(t *testing.T) {

View File

@ -25,7 +25,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestReplica(t *testing.T) {

View File

@ -31,7 +31,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestPGCoordinatorSingle_ClientWithoutAgent(t *testing.T) {

View File

@ -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 {

View File

@ -17,7 +17,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestProvisionerSDK(t *testing.T) {

View File

@ -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) {

View File

@ -11,6 +11,7 @@ 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"
@ -18,7 +19,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestStart(t *testing.T) {

View File

@ -30,7 +30,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestRun(t *testing.T) {

View File

@ -19,7 +19,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestTailnet(t *testing.T) {

View File

@ -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) {

View File

@ -11,7 +11,7 @@ import (
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m, testutil.GoleakOptions...)
}
func TestEventually(t *testing.T) {

18
testutil/goleak.go Normal file
View File

@ -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"),
}

View File

@ -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