diff --git a/go.mod b/go.mod index 37644ea0a5c..424eca9b318 100644 --- a/go.mod +++ b/go.mod @@ -180,6 +180,7 @@ require ( github.com/valyala/fasttemplate v1.0.1 // indirect go.opencensus.io v0.23.0 // indirect go.uber.org/atomic v1.7.0 // indirect + go.uber.org/goleak v1.1.12 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.17.0 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect diff --git a/go.sum b/go.sum index dd899960220..8acbdff7b28 100644 --- a/go.sum +++ b/go.sum @@ -807,6 +807,8 @@ go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= +go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= @@ -1103,6 +1105,7 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.9 h1:j9KsMiaP1c3B0OTQGth0/k+miLGTgLsAFUCrF2vLcF8= golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/go/cache/ristretto/bloom/bbloom_test.go b/go/cache/ristretto/bloom/bbloom_test.go index c0f9a916d10..d7b39bebade 100644 --- a/go/cache/ristretto/bloom/bbloom_test.go +++ b/go/cache/ristretto/bloom/bbloom_test.go @@ -6,6 +6,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/hack" ) @@ -16,6 +18,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) wordlist1 = make([][]byte, n) for i := range wordlist1 { b := make([]byte, 32) diff --git a/go/cmd/vtclient/vtclient.go b/go/cmd/vtclient/vtclient.go index 731a3873e2f..94c948b3808 100644 --- a/go/cmd/vtclient/vtclient.go +++ b/go/cmd/vtclient/vtclient.go @@ -219,6 +219,7 @@ func execMulti(ctx context.Context, db *sql.DB, sql string) (*results, error) { if isThrottled { tickDuration := time.Second / time.Duration(*qps) ticker = time.NewTicker(tickDuration) + defer ticker.Stop() } for j := 0; j < *count; j++ { diff --git a/go/mysql/collations/integration/main_test.go b/go/mysql/collations/integration/main_test.go index c1ceef883e8..e22040f05fc 100644 --- a/go/mysql/collations/integration/main_test.go +++ b/go/mysql/collations/integration/main_test.go @@ -25,6 +25,8 @@ import ( "strings" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/vttest" @@ -55,6 +57,7 @@ func mysqlconn(t *testing.T) *mysql.Conn { } func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) flag.Parse() exitCode := func() int { diff --git a/go/mysql/collations/tools/makecolldata/contractions.go b/go/mysql/collations/tools/makecolldata/contractions.go index 8ac5b27c328..ef8a08fe27d 100644 --- a/go/mysql/collations/tools/makecolldata/contractions.go +++ b/go/mysql/collations/tools/makecolldata/contractions.go @@ -58,7 +58,7 @@ func printContraction1(g *codegen.Generator, wa *weightarray, incont []uca.Contr trie[r] = append(trie[r], cont) } if depth == len(cont.Path) { - leaf = &cont + leaf = &cont // nolint:exportloopref } } diff --git a/go/mysql/endtoend/main_test.go b/go/mysql/endtoend/main_test.go index a18e278a26f..71be48f0361 100644 --- a/go/mysql/endtoend/main_test.go +++ b/go/mysql/endtoend/main_test.go @@ -25,6 +25,8 @@ import ( "strings" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" vtenv "vitess.io/vitess/go/vt/env" "vitess.io/vitess/go/vt/mysqlctl" @@ -169,6 +171,7 @@ func binaryPath(root, binary string) (string, error) { } func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) flag.Parse() // Do not remove this comment, import into google3 depends on it exitCode := func() int { diff --git a/go/stats/prometheusbackend/prometheusbackend_test.go b/go/stats/prometheusbackend/prometheusbackend_test.go index 438e678bb3e..014b8e8dcc1 100644 --- a/go/stats/prometheusbackend/prometheusbackend_test.go +++ b/go/stats/prometheusbackend/prometheusbackend_test.go @@ -25,6 +25,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/stats" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -358,6 +360,7 @@ func testMetricsHandler(t *testing.T) *httptest.ResponseRecorder { } func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) Init(namespace) os.Exit(m.Run()) } diff --git a/go/test/endtoend/backup/transform/backup_transform_test.go b/go/test/endtoend/backup/transform/backup_transform_test.go index 071f7d536e3..601e3fed573 100644 --- a/go/test/endtoend/backup/transform/backup_transform_test.go +++ b/go/test/endtoend/backup/transform/backup_transform_test.go @@ -16,9 +16,14 @@ limitations under the License. package transform -import "testing" +import ( + "testing" + + "go.uber.org/goleak" +) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) TestMainSetup(m, false) } diff --git a/go/test/endtoend/backup/transform/mysqlctld/backup_transform_mysqlctld_test.go b/go/test/endtoend/backup/transform/mysqlctld/backup_transform_mysqlctld_test.go index 0a3b11227da..32901922d95 100644 --- a/go/test/endtoend/backup/transform/mysqlctld/backup_transform_mysqlctld_test.go +++ b/go/test/endtoend/backup/transform/mysqlctld/backup_transform_mysqlctld_test.go @@ -19,10 +19,13 @@ package mysqlctld import ( "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/backup/transform" ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) transform.TestMainSetup(m, true) } diff --git a/go/test/endtoend/backup/vtbackup/main_test.go b/go/test/endtoend/backup/vtbackup/main_test.go index ce0720e77c4..90eab915ed8 100644 --- a/go/test/endtoend/backup/vtbackup/main_test.go +++ b/go/test/endtoend/backup/vtbackup/main_test.go @@ -24,6 +24,8 @@ import ( "path" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/cluster" "vitess.io/vitess/go/vt/log" ) @@ -53,6 +55,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/cellalias/cell_alias_test.go b/go/test/endtoend/cellalias/cell_alias_test.go index 2a2ae3eaa20..1329f5ea7dd 100644 --- a/go/test/endtoend/cellalias/cell_alias_test.go +++ b/go/test/endtoend/cellalias/cell_alias_test.go @@ -31,6 +31,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/test/endtoend/cluster" @@ -92,6 +93,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/cluster/vttablet_process.go b/go/test/endtoend/cluster/vttablet_process.go index 9f1be9255fd..a2c9cd1204d 100644 --- a/go/test/endtoend/cluster/vttablet_process.go +++ b/go/test/endtoend/cluster/vttablet_process.go @@ -203,6 +203,7 @@ func (vttablet *VttabletProcess) GetStatusDetails() string { // WaitForStatus waits till desired status of tablet is reached func (vttablet *VttabletProcess) WaitForStatus(status string, howLong time.Duration) bool { ticker := time.NewTicker(howLong) + defer ticker.Stop() for range ticker.C { if vttablet.GetTabletStatus() == status { return true diff --git a/go/test/endtoend/clustertest/main_test.go b/go/test/endtoend/clustertest/main_test.go index 0be66d56af8..fdae2e71000 100644 --- a/go/test/endtoend/clustertest/main_test.go +++ b/go/test/endtoend/clustertest/main_test.go @@ -22,6 +22,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" ) @@ -60,6 +62,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/keyspace/keyspace_test.go b/go/test/endtoend/keyspace/keyspace_test.go index 82477dacee7..b8d1401a91b 100644 --- a/go/test/endtoend/keyspace/keyspace_test.go +++ b/go/test/endtoend/keyspace/keyspace_test.go @@ -27,6 +27,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/test/endtoend/cluster" "vitess.io/vitess/go/vt/proto/topodata" @@ -79,6 +80,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/messaging/main_test.go b/go/test/endtoend/messaging/main_test.go index 49477ebe631..2e9fd7faac8 100644 --- a/go/test/endtoend/messaging/main_test.go +++ b/go/test/endtoend/messaging/main_test.go @@ -22,6 +22,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/cluster" _ "vitess.io/vitess/go/vt/vtgate/grpcvtgateconn" ) @@ -104,6 +106,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/mysqlctl/mysqlctl_test.go b/go/test/endtoend/mysqlctl/mysqlctl_test.go index a5a446e7f65..2e8d56d6ea5 100644 --- a/go/test/endtoend/mysqlctl/mysqlctl_test.go +++ b/go/test/endtoend/mysqlctl/mysqlctl_test.go @@ -24,6 +24,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/test/endtoend/cluster" ) @@ -39,6 +40,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/mysqlctld/mysqlctld_test.go b/go/test/endtoend/mysqlctld/mysqlctld_test.go index 8c7dfc09d25..c9c971efb06 100644 --- a/go/test/endtoend/mysqlctld/mysqlctld_test.go +++ b/go/test/endtoend/mysqlctld/mysqlctld_test.go @@ -23,6 +23,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/test/endtoend/cluster" ) @@ -38,6 +39,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/mysqlserver/main_test.go b/go/test/endtoend/mysqlserver/main_test.go index 42b4e6ea235..592b0ded756 100644 --- a/go/test/endtoend/mysqlserver/main_test.go +++ b/go/test/endtoend/mysqlserver/main_test.go @@ -23,6 +23,8 @@ import ( "strconv" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" ) @@ -61,6 +63,7 @@ END; ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/onlineddl/declarative/onlineddl_declarative_test.go b/go/test/endtoend/onlineddl/declarative/onlineddl_declarative_test.go index 40e68be96fa..e131e614a39 100644 --- a/go/test/endtoend/onlineddl/declarative/onlineddl_declarative_test.go +++ b/go/test/endtoend/onlineddl/declarative/onlineddl_declarative_test.go @@ -28,6 +28,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/log" "vitess.io/vitess/go/vt/schema" @@ -201,6 +203,7 @@ const ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/onlineddl/ghost/onlineddl_ghost_test.go b/go/test/endtoend/onlineddl/ghost/onlineddl_ghost_test.go index 792e654ea82..6625a5f0bb3 100644 --- a/go/test/endtoend/onlineddl/ghost/onlineddl_ghost_test.go +++ b/go/test/endtoend/onlineddl/ghost/onlineddl_ghost_test.go @@ -26,6 +26,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/schema" @@ -146,6 +148,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/onlineddl/revert/onlineddl_revert_test.go b/go/test/endtoend/onlineddl/revert/onlineddl_revert_test.go index 930c5e6c047..7474037ed5d 100644 --- a/go/test/endtoend/onlineddl/revert/onlineddl_revert_test.go +++ b/go/test/endtoend/onlineddl/revert/onlineddl_revert_test.go @@ -29,6 +29,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/log" "vitess.io/vitess/go/vt/schema" @@ -185,6 +187,7 @@ const ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/onlineddl/revertible/onlineddl_revertible_test.go b/go/test/endtoend/onlineddl/revertible/onlineddl_revertible_test.go index d5918186482..904687cca72 100644 --- a/go/test/endtoend/onlineddl/revertible/onlineddl_revertible_test.go +++ b/go/test/endtoend/onlineddl/revertible/onlineddl_revertible_test.go @@ -25,6 +25,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/schema" @@ -184,6 +186,7 @@ var testCases = []testCase{ } func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go b/go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go index a28b0216a38..10c8b7c65b6 100644 --- a/go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go +++ b/go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go @@ -25,6 +25,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/schema" "vitess.io/vitess/go/vt/sqlparser" @@ -84,6 +86,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/onlineddl/singleton/onlineddl_singleton_test.go b/go/test/endtoend/onlineddl/singleton/onlineddl_singleton_test.go index 8b30dc09933..0e8208280ad 100644 --- a/go/test/endtoend/onlineddl/singleton/onlineddl_singleton_test.go +++ b/go/test/endtoend/onlineddl/singleton/onlineddl_singleton_test.go @@ -25,6 +25,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/schema" @@ -82,6 +84,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/onlineddl/vrepl/onlineddl_vrepl_test.go b/go/test/endtoend/onlineddl/vrepl/onlineddl_vrepl_test.go index 7942d30b6b2..a9d84c98b69 100644 --- a/go/test/endtoend/onlineddl/vrepl/onlineddl_vrepl_test.go +++ b/go/test/endtoend/onlineddl/vrepl/onlineddl_vrepl_test.go @@ -28,6 +28,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" "vitess.io/vitess/go/test/endtoend/onlineddl" @@ -152,6 +154,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/onlineddl/vrepl_stress/onlineddl_vrepl_mini_stress_test.go b/go/test/endtoend/onlineddl/vrepl_stress/onlineddl_vrepl_mini_stress_test.go index 1d69f043467..707ff5129b5 100644 --- a/go/test/endtoend/onlineddl/vrepl_stress/onlineddl_vrepl_mini_stress_test.go +++ b/go/test/endtoend/onlineddl/vrepl_stress/onlineddl_vrepl_mini_stress_test.go @@ -29,6 +29,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/log" "vitess.io/vitess/go/vt/schema" @@ -156,6 +158,7 @@ func nextOpOrder() int64 { } func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/onlineddl/vrepl_stress_suite/onlineddl_vrepl_stress_suite_test.go b/go/test/endtoend/onlineddl/vrepl_stress_suite/onlineddl_vrepl_stress_suite_test.go index cf194e9f630..ce8774bea6c 100644 --- a/go/test/endtoend/onlineddl/vrepl_stress_suite/onlineddl_vrepl_stress_suite_test.go +++ b/go/test/endtoend/onlineddl/vrepl_stress_suite/onlineddl_vrepl_stress_suite_test.go @@ -40,6 +40,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/log" "vitess.io/vitess/go/vt/schema" @@ -404,6 +406,7 @@ func mysqlParams() *mysql.ConnParams { } func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/onlineddl/vrepl_suite/onlineddl_vrepl_suite_test.go b/go/test/endtoend/onlineddl/vrepl_suite/onlineddl_vrepl_suite_test.go index 5424f05c935..272b2651af8 100644 --- a/go/test/endtoend/onlineddl/vrepl_suite/onlineddl_vrepl_suite_test.go +++ b/go/test/endtoend/onlineddl/vrepl_suite/onlineddl_vrepl_suite_test.go @@ -27,6 +27,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/schema" @@ -62,6 +64,7 @@ const ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/preparestmt/main_test.go b/go/test/endtoend/preparestmt/main_test.go index 018e9d266fd..4e2c5a012c2 100644 --- a/go/test/endtoend/preparestmt/main_test.go +++ b/go/test/endtoend/preparestmt/main_test.go @@ -27,6 +27,7 @@ import ( "github.com/go-sql-driver/mysql" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/test/endtoend/cluster" ) @@ -162,6 +163,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/recovery/unshardedrecovery/recovery.go b/go/test/endtoend/recovery/unshardedrecovery/recovery.go index db76cc3654f..9beae8fab7f 100644 --- a/go/test/endtoend/recovery/unshardedrecovery/recovery.go +++ b/go/test/endtoend/recovery/unshardedrecovery/recovery.go @@ -27,6 +27,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/test/endtoend/cluster" "vitess.io/vitess/go/test/endtoend/recovery" @@ -72,6 +73,7 @@ var ( // TestMainImpl creates cluster for unsharded recovery testing. func TestMainImpl(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/recovery/unshardedrecovery/recovery_test.go b/go/test/endtoend/recovery/unshardedrecovery/recovery_test.go index 86079a6eb54..be83047cd0e 100644 --- a/go/test/endtoend/recovery/unshardedrecovery/recovery_test.go +++ b/go/test/endtoend/recovery/unshardedrecovery/recovery_test.go @@ -19,10 +19,13 @@ package unshardedrecovery import ( "testing" + "go.uber.org/goleak" + _ "vitess.io/vitess/go/vt/vtgate/grpcvtgateconn" ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) TestMainImpl(m) } diff --git a/go/test/endtoend/recovery/xtrabackup/recovery_test.go b/go/test/endtoend/recovery/xtrabackup/recovery_test.go index 940fc5ad7e2..67ccf361bc5 100644 --- a/go/test/endtoend/recovery/xtrabackup/recovery_test.go +++ b/go/test/endtoend/recovery/xtrabackup/recovery_test.go @@ -19,12 +19,15 @@ package xtrabackup import ( "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/recovery" "vitess.io/vitess/go/test/endtoend/recovery/unshardedrecovery" _ "vitess.io/vitess/go/vt/vtgate/grpcvtgateconn" ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) recovery.UseXb = true unshardedrecovery.TestMainImpl(m) } diff --git a/go/test/endtoend/reparent/utils/utils.go b/go/test/endtoend/reparent/utils/utils.go index a716183017d..97b5b01cd15 100644 --- a/go/test/endtoend/reparent/utils/utils.go +++ b/go/test/endtoend/reparent/utils/utils.go @@ -515,6 +515,7 @@ func GetShardReplicationPositions(t *testing.T, clusterInstance *cluster.LocalPr func WaitForReplicationToStart(t *testing.T, clusterInstance *cluster.LocalProcessCluster, keyspaceName, shardName string, tabletCnt int, doPrint bool) { tck := time.NewTicker(500 * time.Millisecond) + defer tck.Stop() for { select { case <-tck.C: diff --git a/go/test/endtoend/schemadiff/vrepl/schemadiff_vrepl_suite_test.go b/go/test/endtoend/schemadiff/vrepl/schemadiff_vrepl_suite_test.go index 90fadb01f6b..7c3ce4cd312 100644 --- a/go/test/endtoend/schemadiff/vrepl/schemadiff_vrepl_suite_test.go +++ b/go/test/endtoend/schemadiff/vrepl/schemadiff_vrepl_suite_test.go @@ -28,6 +28,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/sqltypes" @@ -67,6 +68,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/sharded/sharded_keyspace_test.go b/go/test/endtoend/sharded/sharded_keyspace_test.go index 945b4179846..7899162b597 100644 --- a/go/test/endtoend/sharded/sharded_keyspace_test.go +++ b/go/test/endtoend/sharded/sharded_keyspace_test.go @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/test/endtoend/cluster" "vitess.io/vitess/go/vt/log" @@ -72,6 +73,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/stress/stress_test.go b/go/test/endtoend/stress/stress_test.go index 30a5ee69c1a..e41edc91ba4 100644 --- a/go/test/endtoend/stress/stress_test.go +++ b/go/test/endtoend/stress/stress_test.go @@ -21,6 +21,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/stress" "vitess.io/vitess/go/mysql" @@ -42,6 +44,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/tabletgateway/main_test.go b/go/test/endtoend/tabletgateway/main_test.go index da4fe711f64..4ed432649c2 100644 --- a/go/test/endtoend/tabletgateway/main_test.go +++ b/go/test/endtoend/tabletgateway/main_test.go @@ -21,6 +21,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" ) @@ -59,6 +61,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/tabletmanager/main_test.go b/go/test/endtoend/tabletmanager/main_test.go index 7dcfa4ea1a5..41287c62575 100644 --- a/go/test/endtoend/tabletmanager/main_test.go +++ b/go/test/endtoend/tabletmanager/main_test.go @@ -25,6 +25,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" tabletpb "vitess.io/vitess/go/vt/proto/topodata" @@ -79,6 +81,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/tabletmanager/primary/tablet_test.go b/go/test/endtoend/tabletmanager/primary/tablet_test.go index 81189196c69..5b583430472 100644 --- a/go/test/endtoend/tabletmanager/primary/tablet_test.go +++ b/go/test/endtoend/tabletmanager/primary/tablet_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/json2" "vitess.io/vitess/go/test/endtoend/cluster" @@ -72,6 +74,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/tabletmanager/tablegc/tablegc_test.go b/go/test/endtoend/tabletmanager/tablegc/tablegc_test.go index 3cee94ff7ca..465b3c950a1 100644 --- a/go/test/endtoend/tabletmanager/tablegc/tablegc_test.go +++ b/go/test/endtoend/tabletmanager/tablegc/tablegc_test.go @@ -22,6 +22,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/schema" "vitess.io/vitess/go/vt/sqlparser" @@ -79,6 +81,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() @@ -179,6 +182,7 @@ func validateTableDoesNotExist(t *testing.T, tableExpr string) { defer cancel() ticker := time.NewTicker(time.Second) + defer ticker.Stop() var foundTableName string var exists bool var err error @@ -202,6 +206,7 @@ func validateTableExists(t *testing.T, tableExpr string) { defer cancel() ticker := time.NewTicker(time.Second) + defer ticker.Stop() var exists bool var err error for { diff --git a/go/test/endtoend/tabletmanager/throttler/throttler_test.go b/go/test/endtoend/tabletmanager/throttler/throttler_test.go index 4b03e624d18..acac59d61c6 100644 --- a/go/test/endtoend/tabletmanager/throttler/throttler_test.go +++ b/go/test/endtoend/tabletmanager/throttler/throttler_test.go @@ -24,6 +24,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/base" "vitess.io/vitess/go/test/endtoend/cluster" @@ -81,6 +83,7 @@ const ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/tabletmanager/throttler_custom_config/throttler_test.go b/go/test/endtoend/tabletmanager/throttler_custom_config/throttler_test.go index 743dd4288c5..79e10584a2b 100644 --- a/go/test/endtoend/tabletmanager/throttler_custom_config/throttler_test.go +++ b/go/test/endtoend/tabletmanager/throttler_custom_config/throttler_test.go @@ -24,6 +24,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/base" @@ -81,6 +83,7 @@ const ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/topoconncache/main_test.go b/go/test/endtoend/topoconncache/main_test.go index 31304bc6694..3f670ec6cb0 100644 --- a/go/test/endtoend/topoconncache/main_test.go +++ b/go/test/endtoend/topoconncache/main_test.go @@ -29,6 +29,8 @@ import ( "os/exec" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/cluster" ) @@ -97,6 +99,7 @@ Topology: We create a keyspace with two shards , having 3 tablets each. Primarie to 'zone1' and replicas/rdonly belongs to cell2. */ func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/topotest/consul/main_test.go b/go/test/endtoend/topotest/consul/main_test.go index 1c278864ced..aefd72cd424 100644 --- a/go/test/endtoend/topotest/consul/main_test.go +++ b/go/test/endtoend/topotest/consul/main_test.go @@ -24,6 +24,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/vt/log" "github.com/google/go-cmp/cmp" @@ -61,6 +63,7 @@ CREATE TABLE t1 ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/topotest/etcd2/main_test.go b/go/test/endtoend/topotest/etcd2/main_test.go index db34bd2ee86..49c2663cdb6 100644 --- a/go/test/endtoend/topotest/etcd2/main_test.go +++ b/go/test/endtoend/topotest/etcd2/main_test.go @@ -23,6 +23,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "vitess.io/vitess/go/vt/log" @@ -61,6 +63,7 @@ CREATE TABLE t1 ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/topotest/zk2/main_test.go b/go/test/endtoend/topotest/zk2/main_test.go index 816bbc72d72..b0ae00df0ee 100644 --- a/go/test/endtoend/topotest/zk2/main_test.go +++ b/go/test/endtoend/topotest/zk2/main_test.go @@ -23,6 +23,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "vitess.io/vitess/go/vt/log" @@ -61,6 +63,7 @@ CREATE TABLE t1 ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/utils/mysql_test.go b/go/test/endtoend/utils/mysql_test.go index d2816cb1227..c3b85625457 100644 --- a/go/test/endtoend/utils/mysql_test.go +++ b/go/test/endtoend/utils/mysql_test.go @@ -23,6 +23,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" @@ -42,6 +43,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) exitCode := func() int { diff --git a/go/test/endtoend/utils/mysqlvsvitess/main_test.go b/go/test/endtoend/utils/mysqlvsvitess/main_test.go index f59132c3858..28047c62aa6 100644 --- a/go/test/endtoend/utils/mysqlvsvitess/main_test.go +++ b/go/test/endtoend/utils/mysqlvsvitess/main_test.go @@ -23,6 +23,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" @@ -64,6 +65,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) exitCode := func() int { diff --git a/go/test/endtoend/versionupgrade/upgrade_test.go b/go/test/endtoend/versionupgrade/upgrade_test.go index bf7108a8291..faca7b7054d 100644 --- a/go/test/endtoend/versionupgrade/upgrade_test.go +++ b/go/test/endtoend/versionupgrade/upgrade_test.go @@ -42,6 +42,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" @@ -72,6 +73,7 @@ var ( // TestMain is the main entry point func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vreplication/helper_test.go b/go/test/endtoend/vreplication/helper_test.go index 9ecfa5b050f..846c9c51301 100644 --- a/go/test/endtoend/vreplication/helper_test.go +++ b/go/test/endtoend/vreplication/helper_test.go @@ -95,6 +95,7 @@ func checkHealth(t *testing.T, url string) bool { func waitForQueryToExecute(t *testing.T, conn *mysql.Conn, database string, query string, want string) { done := false ticker := time.NewTicker(10 * time.Millisecond) + defer ticker.Stop() for { select { case <-ticker.C: diff --git a/go/test/endtoend/vreplication/resharding_workflows_v2_test.go b/go/test/endtoend/vreplication/resharding_workflows_v2_test.go index 0c78dc62312..34bf07060a4 100644 --- a/go/test/endtoend/vreplication/resharding_workflows_v2_test.go +++ b/go/test/endtoend/vreplication/resharding_workflows_v2_test.go @@ -261,7 +261,9 @@ const workflowStartTimeout = 5 * time.Second func waitForWorkflowToStart(t *testing.T, ksWorkflow string) { done := false ticker := time.NewTicker(100 * time.Millisecond) + defer ticker.Stop() timer := time.NewTimer(workflowStartTimeout) + defer timer.Stop() log.Infof("Waiting for workflow %s to start", ksWorkflow) for { select { diff --git a/go/test/endtoend/vreplication/vstream_test.go b/go/test/endtoend/vreplication/vstream_test.go index c596ed084f7..0bf68ad5fc9 100644 --- a/go/test/endtoend/vreplication/vstream_test.go +++ b/go/test/endtoend/vreplication/vstream_test.go @@ -133,6 +133,7 @@ func testVStreamWithFailover(t *testing.T, failover bool) { // run two PRS after one second each, wait for events to be received and exit test ticker := time.NewTicker(1 * time.Second) + defer ticker.Stop() tickCount := 0 // this for loop implements a mini state machine that does the two PRSs, waits a bit after the second PRS, // stops the insertions, waits for a bit again for the vstream to catchup and signals the test to stop @@ -358,6 +359,7 @@ func testVStreamStopOnReshardFlag(t *testing.T, stopOnReshard bool, baseTabletID }() ticker := time.NewTicker(1 * time.Second) + defer ticker.Stop() tickCount := 0 for { <-ticker.C diff --git a/go/test/endtoend/vtgate/concurrentdml/main_test.go b/go/test/endtoend/vtgate/concurrentdml/main_test.go index 6ee5619b742..730b8fe123a 100644 --- a/go/test/endtoend/vtgate/concurrentdml/main_test.go +++ b/go/test/endtoend/vtgate/concurrentdml/main_test.go @@ -26,6 +26,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/assert" @@ -66,6 +68,7 @@ INSERT INTO t1_seq (id, next_id, cache) values(0, 1, 1000); ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/createdb_plugin/main_test.go b/go/test/endtoend/vtgate/createdb_plugin/main_test.go index e712fee7b36..c283148b9d8 100644 --- a/go/test/endtoend/vtgate/createdb_plugin/main_test.go +++ b/go/test/endtoend/vtgate/createdb_plugin/main_test.go @@ -24,6 +24,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/assert" @@ -43,6 +45,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/errors_as_warnings/main_test.go b/go/test/endtoend/vtgate/errors_as_warnings/main_test.go index 9b37aac4151..51c718a2ae8 100644 --- a/go/test/endtoend/vtgate/errors_as_warnings/main_test.go +++ b/go/test/endtoend/vtgate/errors_as_warnings/main_test.go @@ -24,6 +24,8 @@ import ( "strings" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/require" @@ -65,6 +67,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/gen4/main_test.go b/go/test/endtoend/vtgate/gen4/main_test.go index cc50cbba40a..778b1d18604 100644 --- a/go/test/endtoend/vtgate/gen4/main_test.go +++ b/go/test/endtoend/vtgate/gen4/main_test.go @@ -24,6 +24,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/test/endtoend/utils" @@ -64,6 +65,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/godriver/main_test.go b/go/test/endtoend/vtgate/godriver/main_test.go index bbc5536a3fa..d2ccd2d33d3 100644 --- a/go/test/endtoend/vtgate/godriver/main_test.go +++ b/go/test/endtoend/vtgate/godriver/main_test.go @@ -26,6 +26,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "google.golang.org/grpc" "google.golang.org/grpc/keepalive" @@ -86,6 +87,7 @@ create table my_message( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/main_test.go b/go/test/endtoend/vtgate/main_test.go index ae644e26882..2c9c9641d9c 100644 --- a/go/test/endtoend/vtgate/main_test.go +++ b/go/test/endtoend/vtgate/main_test.go @@ -22,6 +22,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" ) @@ -49,6 +51,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/mysql80/derived/main_test.go b/go/test/endtoend/vtgate/mysql80/derived/main_test.go index 7006f3980fa..b7ebd562a6d 100644 --- a/go/test/endtoend/vtgate/mysql80/derived/main_test.go +++ b/go/test/endtoend/vtgate/mysql80/derived/main_test.go @@ -21,6 +21,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" ) @@ -86,6 +88,7 @@ create table t1_id2_idx( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/mysql80/main_test.go b/go/test/endtoend/vtgate/mysql80/main_test.go index 4f5897d1f59..5ce0c197f6d 100644 --- a/go/test/endtoend/vtgate/mysql80/main_test.go +++ b/go/test/endtoend/vtgate/mysql80/main_test.go @@ -21,6 +21,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + querypb "vitess.io/vitess/go/vt/proto/query" "vitess.io/vitess/go/mysql" @@ -35,6 +37,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/partialfailure/main_test.go b/go/test/endtoend/vtgate/partialfailure/main_test.go index 103847dcb2f..86597faacff 100644 --- a/go/test/endtoend/vtgate/partialfailure/main_test.go +++ b/go/test/endtoend/vtgate/partialfailure/main_test.go @@ -22,6 +22,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/require" @@ -100,6 +102,7 @@ CREATE TABLE test_vdx ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/prefixfanout/main_test.go b/go/test/endtoend/vtgate/prefixfanout/main_test.go index f42f556ea7e..20aff012776 100644 --- a/go/test/endtoend/vtgate/prefixfanout/main_test.go +++ b/go/test/endtoend/vtgate/prefixfanout/main_test.go @@ -19,6 +19,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/assert" @@ -107,6 +109,7 @@ PRIMARY KEY (c1) ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/queries/aggregation/main_test.go b/go/test/endtoend/vtgate/queries/aggregation/main_test.go index 93968e861f7..7f84f595d2b 100644 --- a/go/test/endtoend/vtgate/queries/aggregation/main_test.go +++ b/go/test/endtoend/vtgate/queries/aggregation/main_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "vitess.io/vitess/go/mysql" @@ -44,6 +46,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/queries/foundrows/main_test.go b/go/test/endtoend/vtgate/queries/foundrows/main_test.go index f9266036810..8608ac34bf9 100644 --- a/go/test/endtoend/vtgate/queries/foundrows/main_test.go +++ b/go/test/endtoend/vtgate/queries/foundrows/main_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "vitess.io/vitess/go/mysql" @@ -46,6 +48,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/queries/informationschema/main_test.go b/go/test/endtoend/vtgate/queries/informationschema/main_test.go index 5ae026b095e..f6fd4f183fe 100644 --- a/go/test/endtoend/vtgate/queries/informationschema/main_test.go +++ b/go/test/endtoend/vtgate/queries/informationschema/main_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "vitess.io/vitess/go/mysql" @@ -52,6 +54,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/queries/insert/main_test.go b/go/test/endtoend/vtgate/queries/insert/main_test.go index 27e823893b7..78246edfbc2 100644 --- a/go/test/endtoend/vtgate/queries/insert/main_test.go +++ b/go/test/endtoend/vtgate/queries/insert/main_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/vt/vtgate/planbuilder" "vitess.io/vitess/go/test/endtoend/utils" @@ -63,6 +65,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/queries/misc/main_test.go b/go/test/endtoend/vtgate/queries/misc/main_test.go index 35577db62a4..07be3369d58 100644 --- a/go/test/endtoend/vtgate/queries/misc/main_test.go +++ b/go/test/endtoend/vtgate/queries/misc/main_test.go @@ -22,6 +22,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "vitess.io/vitess/go/mysql" @@ -63,6 +65,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/queries/normalize/main_test.go b/go/test/endtoend/vtgate/queries/normalize/main_test.go index ddb623a6c47..9ec479007b6 100644 --- a/go/test/endtoend/vtgate/queries/normalize/main_test.go +++ b/go/test/endtoend/vtgate/queries/normalize/main_test.go @@ -21,6 +21,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" ) @@ -53,6 +55,7 @@ create table t1( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/queries/orderby/main_test.go b/go/test/endtoend/vtgate/queries/orderby/main_test.go index f3b697e0988..99121aa236f 100644 --- a/go/test/endtoend/vtgate/queries/orderby/main_test.go +++ b/go/test/endtoend/vtgate/queries/orderby/main_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "vitess.io/vitess/go/mysql" @@ -44,6 +46,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/queries/subquery/main_test.go b/go/test/endtoend/vtgate/queries/subquery/main_test.go index ce745f4fb79..98ccfdaeacb 100644 --- a/go/test/endtoend/vtgate/queries/subquery/main_test.go +++ b/go/test/endtoend/vtgate/queries/subquery/main_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "vitess.io/vitess/go/mysql" @@ -44,6 +46,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/queries/union/main_test.go b/go/test/endtoend/vtgate/queries/union/main_test.go index 4fe378f0073..ba33cce8414 100644 --- a/go/test/endtoend/vtgate/queries/union/main_test.go +++ b/go/test/endtoend/vtgate/queries/union/main_test.go @@ -22,6 +22,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "vitess.io/vitess/go/mysql" @@ -134,6 +136,7 @@ create table t2_id4_idx( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/readafterwrite/raw_test.go b/go/test/endtoend/vtgate/readafterwrite/raw_test.go index 9d9eefff7cb..d7620a3715f 100644 --- a/go/test/endtoend/vtgate/readafterwrite/raw_test.go +++ b/go/test/endtoend/vtgate/readafterwrite/raw_test.go @@ -22,6 +22,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/require" @@ -100,6 +102,7 @@ CREATE TABLE test_vdx ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/reservedconn/main_test.go b/go/test/endtoend/vtgate/reservedconn/main_test.go index 2dcd66109fc..81c43d060fd 100644 --- a/go/test/endtoend/vtgate/reservedconn/main_test.go +++ b/go/test/endtoend/vtgate/reservedconn/main_test.go @@ -22,6 +22,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/assert" @@ -100,6 +102,7 @@ CREATE TABLE test_vdx ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/reservedconn/reconnect1/main_test.go b/go/test/endtoend/vtgate/reservedconn/reconnect1/main_test.go index db777a73d40..4784309d623 100644 --- a/go/test/endtoend/vtgate/reservedconn/reconnect1/main_test.go +++ b/go/test/endtoend/vtgate/reservedconn/reconnect1/main_test.go @@ -22,6 +22,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/assert" @@ -63,6 +65,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/reservedconn/reconnect2/main_test.go b/go/test/endtoend/vtgate/reservedconn/reconnect2/main_test.go index fb89ea69551..c669ade0c61 100644 --- a/go/test/endtoend/vtgate/reservedconn/reconnect2/main_test.go +++ b/go/test/endtoend/vtgate/reservedconn/reconnect2/main_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/assert" @@ -64,6 +66,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/reservedconn/reconnect3/main_test.go b/go/test/endtoend/vtgate/reservedconn/reconnect3/main_test.go index ff0e675086d..54198191c01 100644 --- a/go/test/endtoend/vtgate/reservedconn/reconnect3/main_test.go +++ b/go/test/endtoend/vtgate/reservedconn/reconnect3/main_test.go @@ -22,6 +22,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/require" @@ -40,6 +42,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/schema/schema_test.go b/go/test/endtoend/vtgate/schema/schema_test.go index a452f66b2b5..fe102abcc76 100644 --- a/go/test/endtoend/vtgate/schema/schema_test.go +++ b/go/test/endtoend/vtgate/schema/schema_test.go @@ -29,6 +29,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/test/endtoend/cluster" ) @@ -55,6 +56,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/schematracker/restarttablet/schema_restart_test.go b/go/test/endtoend/vtgate/schematracker/restarttablet/schema_restart_test.go index 9d3de02f846..a6877e3dd37 100644 --- a/go/test/endtoend/vtgate/schematracker/restarttablet/schema_restart_test.go +++ b/go/test/endtoend/vtgate/schematracker/restarttablet/schema_restart_test.go @@ -26,6 +26,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/require" @@ -65,6 +67,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go b/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go index ee5b10483f1..b106bbdc94b 100644 --- a/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go +++ b/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go @@ -23,6 +23,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/require" @@ -119,6 +121,7 @@ create table t8( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/schematracker/sharded_prs/st_sharded_test.go b/go/test/endtoend/vtgate/schematracker/sharded_prs/st_sharded_test.go index f77a320bbc7..22a9fc67561 100644 --- a/go/test/endtoend/vtgate/schematracker/sharded_prs/st_sharded_test.go +++ b/go/test/endtoend/vtgate/schematracker/sharded_prs/st_sharded_test.go @@ -24,6 +24,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" "vitess.io/vitess/go/vt/vterrors" @@ -123,6 +125,7 @@ create table t8( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/schematracker/unauthorized/unauthorized_test.go b/go/test/endtoend/vtgate/schematracker/unauthorized/unauthorized_test.go index 276664c74fd..8ea05e4f917 100644 --- a/go/test/endtoend/vtgate/schematracker/unauthorized/unauthorized_test.go +++ b/go/test/endtoend/vtgate/schematracker/unauthorized/unauthorized_test.go @@ -27,6 +27,7 @@ import ( "time" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" @@ -46,6 +47,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/schematracker/unsharded/st_unsharded_test.go b/go/test/endtoend/vtgate/schematracker/unsharded/st_unsharded_test.go index 930f288b831..0b57606b542 100644 --- a/go/test/endtoend/vtgate/schematracker/unsharded/st_unsharded_test.go +++ b/go/test/endtoend/vtgate/schematracker/unsharded/st_unsharded_test.go @@ -23,6 +23,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/require" @@ -46,6 +48,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/sec_vind/main_test.go b/go/test/endtoend/vtgate/sec_vind/main_test.go index 7aa5df76a83..8c39115cc06 100644 --- a/go/test/endtoend/vtgate/sec_vind/main_test.go +++ b/go/test/endtoend/vtgate/sec_vind/main_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/require" @@ -44,6 +46,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/sequence/seq_test.go b/go/test/endtoend/vtgate/sequence/seq_test.go index 0d72b870955..ff35a37bb69 100644 --- a/go/test/endtoend/vtgate/sequence/seq_test.go +++ b/go/test/endtoend/vtgate/sequence/seq_test.go @@ -24,6 +24,8 @@ import ( "strings" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/assert" @@ -173,6 +175,7 @@ CREATE TABLE allDefaults ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/tablet_healthcheck_cache/correctness_test.go b/go/test/endtoend/vtgate/tablet_healthcheck_cache/correctness_test.go index 0ae8ebeb886..6a06ca4e497 100644 --- a/go/test/endtoend/vtgate/tablet_healthcheck_cache/correctness_test.go +++ b/go/test/endtoend/vtgate/tablet_healthcheck_cache/correctness_test.go @@ -27,6 +27,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" @@ -86,6 +87,7 @@ create table corder( // TestMain sets up the vitess cluster for any subsequent tests func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/transaction/rollback/txn_rollback_shutdown_test.go b/go/test/endtoend/vtgate/transaction/rollback/txn_rollback_shutdown_test.go index c9675aae7e2..9feade69493 100644 --- a/go/test/endtoend/vtgate/transaction/rollback/txn_rollback_shutdown_test.go +++ b/go/test/endtoend/vtgate/transaction/rollback/txn_rollback_shutdown_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/require" @@ -48,6 +50,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/transaction/single/main_test.go b/go/test/endtoend/vtgate/transaction/single/main_test.go index 523fb8ffe49..94a0e43b0f3 100644 --- a/go/test/endtoend/vtgate/transaction/single/main_test.go +++ b/go/test/endtoend/vtgate/transaction/single/main_test.go @@ -24,6 +24,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/test/endtoend/utils" @@ -45,6 +46,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/transaction/trxn_mode_test.go b/go/test/endtoend/vtgate/transaction/trxn_mode_test.go index cc3928cb5a4..47015ab5308 100644 --- a/go/test/endtoend/vtgate/transaction/trxn_mode_test.go +++ b/go/test/endtoend/vtgate/transaction/trxn_mode_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/require" @@ -95,6 +97,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/unsharded/main_test.go b/go/test/endtoend/vtgate/unsharded/main_test.go index 3a86d9ef00b..91e3869b328 100644 --- a/go/test/endtoend/vtgate/unsharded/main_test.go +++ b/go/test/endtoend/vtgate/unsharded/main_test.go @@ -23,6 +23,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "vitess.io/vitess/go/vt/log" @@ -148,6 +150,7 @@ END; ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/vindex_bindvars/main_test.go b/go/test/endtoend/vtgate/vindex_bindvars/main_test.go index 7900d155932..407d6f0dcf2 100644 --- a/go/test/endtoend/vtgate/vindex_bindvars/main_test.go +++ b/go/test/endtoend/vtgate/vindex_bindvars/main_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/require" @@ -149,6 +151,7 @@ CREATE TABLE thex ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtgate/vschema/vschema_test.go b/go/test/endtoend/vtgate/vschema/vschema_test.go index 80a29c6aff4..f7baf6e3645 100644 --- a/go/test/endtoend/vtgate/vschema/vschema_test.go +++ b/go/test/endtoend/vtgate/vschema/vschema_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/utils" "github.com/stretchr/testify/require" @@ -53,6 +55,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) defer cluster.PanicHandler(nil) flag.Parse() diff --git a/go/test/endtoend/vtorc/general/main_test.go b/go/test/endtoend/vtorc/general/main_test.go index 018e6da21fa..f8c279314b4 100644 --- a/go/test/endtoend/vtorc/general/main_test.go +++ b/go/test/endtoend/vtorc/general/main_test.go @@ -21,6 +21,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/cluster" "vitess.io/vitess/go/test/endtoend/vtorc/utils" ) @@ -28,6 +30,7 @@ import ( var clusterInfo *utils.VtOrcClusterInfo func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) // setup cellInfos before creating the cluster var cellInfos []*utils.CellInfo cellInfos = append(cellInfos, &utils.CellInfo{ diff --git a/go/test/endtoend/vtorc/gracefultakeover/main_test.go b/go/test/endtoend/vtorc/gracefultakeover/main_test.go index d429e36a35b..337e7252fa4 100644 --- a/go/test/endtoend/vtorc/gracefultakeover/main_test.go +++ b/go/test/endtoend/vtorc/gracefultakeover/main_test.go @@ -21,6 +21,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/cluster" "vitess.io/vitess/go/test/endtoend/vtorc/utils" ) @@ -28,6 +30,7 @@ import ( var clusterInfo *utils.VtOrcClusterInfo func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) // setup cellInfos before creating the cluster var cellInfos []*utils.CellInfo cellInfos = append(cellInfos, &utils.CellInfo{ diff --git a/go/test/endtoend/vtorc/primaryfailure/main_test.go b/go/test/endtoend/vtorc/primaryfailure/main_test.go index 73a159ceda7..1a763913141 100644 --- a/go/test/endtoend/vtorc/primaryfailure/main_test.go +++ b/go/test/endtoend/vtorc/primaryfailure/main_test.go @@ -21,6 +21,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/test/endtoend/vtorc/utils" "vitess.io/vitess/go/test/endtoend/cluster" @@ -29,6 +31,7 @@ import ( var clusterInfo *utils.VtOrcClusterInfo func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) // setup cellInfos before creating the cluster var cellInfos []*utils.CellInfo cellInfos = append(cellInfos, &utils.CellInfo{ diff --git a/go/vt/discovery/healthcheck_test.go b/go/vt/discovery/healthcheck_test.go index 8606eb85bd7..fe361ead5ad 100644 --- a/go/vt/discovery/healthcheck_test.go +++ b/go/vt/discovery/healthcheck_test.go @@ -442,6 +442,7 @@ func TestHealthCheckVerifiesTabletAlias(t *testing.T) { } ticker := time.NewTicker(1 * time.Second) + defer ticker.Stop() select { case err := <-fc.cbErrCh: assert.Contains(t, err.Error(), "health stats mismatch", "wrong error") diff --git a/go/vt/logutil/purge.go b/go/vt/logutil/purge.go index a450b0ae2a3..b3aa6987a1d 100644 --- a/go/vt/logutil/purge.go +++ b/go/vt/logutil/purge.go @@ -113,6 +113,7 @@ func PurgeLogs() { logDir := f.Value.String() program := filepath.Base(os.Args[0]) ticker := time.NewTicker(*purgeLogsInterval) + defer ticker.Stop() for range ticker.C { purgeLogsOnce(time.Now(), logDir, program, *keepLogsByCtime, *keepLogsByMtime) } diff --git a/go/vt/vitessdriver/driver_test.go b/go/vt/vitessdriver/driver_test.go index 5438aa0c75d..ffc64c2bafd 100644 --- a/go/vt/vitessdriver/driver_test.go +++ b/go/vt/vitessdriver/driver_test.go @@ -29,6 +29,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" "github.com/stretchr/testify/require" "google.golang.org/grpc" @@ -48,6 +49,7 @@ var ( // have to be. The main point here is to test the interactions against a // vtgate implementation (here: fakeVTGateService from fakeserver_test.go). func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) service := CreateFakeServer() // listen on a random port. diff --git a/go/vt/vtgate/endtoend/deletetest/delete_test.go b/go/vt/vtgate/endtoend/deletetest/delete_test.go index 82c9c359c5b..49280525b3b 100644 --- a/go/vt/vtgate/endtoend/deletetest/delete_test.go +++ b/go/vt/vtgate/endtoend/deletetest/delete_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/vt/log" "vitess.io/vitess/go/mysql" @@ -116,6 +118,7 @@ create table del_test_b( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) flag.Parse() exitCode := func() int { diff --git a/go/vt/vtgate/endtoend/main_test.go b/go/vt/vtgate/endtoend/main_test.go index df604c003cc..79cb35bf93c 100644 --- a/go/vt/vtgate/endtoend/main_test.go +++ b/go/vt/vtgate/endtoend/main_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/vttest" @@ -197,6 +199,7 @@ create table t1_sharded( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) flag.Parse() exitCode := func() int { diff --git a/go/vt/vtgate/endtoend/update/lookup_unique_test.go b/go/vt/vtgate/endtoend/update/lookup_unique_test.go index 88ada23b689..f6a0d496efc 100644 --- a/go/vt/vtgate/endtoend/update/lookup_unique_test.go +++ b/go/vt/vtgate/endtoend/update/lookup_unique_test.go @@ -24,6 +24,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/test/endtoend/utils" "vitess.io/vitess/go/vt/log" @@ -131,6 +132,7 @@ create table t2_id_idx( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) flag.Parse() exitCode := func() int { diff --git a/go/vt/vtgate/status.go b/go/vt/vtgate/status.go index 40c545b0107..3efe7e5be97 100644 --- a/go/vt/vtgate/status.go +++ b/go/vt/vtgate/status.go @@ -105,6 +105,7 @@ func registerAggregator(a *TabletStatusAggregator) { // resetAggregators resets the next stats slot for all aggregators every second. func resetAggregators() { ticker := time.NewTicker(time.Second) + defer ticker.Stop() for range ticker.C { muAggr.Lock() for _, a := range aggregators { diff --git a/go/vt/vttablet/endtoend/connkilling/main_test.go b/go/vt/vttablet/endtoend/connkilling/main_test.go index 5f1d20beffe..267e68ed031 100644 --- a/go/vt/vttablet/endtoend/connkilling/main_test.go +++ b/go/vt/vttablet/endtoend/connkilling/main_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/tableacl" "vitess.io/vitess/go/vt/tableacl/simpleacl" @@ -39,6 +41,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) flag.Parse() // Do not remove this comment, import into google3 depends on it tabletenv.Init() diff --git a/go/vt/vttablet/endtoend/main_test.go b/go/vt/vttablet/endtoend/main_test.go index efe934a08b3..c05a1ada09d 100644 --- a/go/vt/vttablet/endtoend/main_test.go +++ b/go/vt/vttablet/endtoend/main_test.go @@ -23,6 +23,8 @@ import ( "os" "testing" + "go.uber.org/goleak" + "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/tableacl" "vitess.io/vitess/go/vt/tableacl/simpleacl" @@ -39,6 +41,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) flag.Parse() // Do not remove this comment, import into google3 depends on it tabletenv.Init() diff --git a/go/vt/vttablet/tabletmanager/vreplication/framework_test.go b/go/vt/vttablet/tabletmanager/vreplication/framework_test.go index dc78f92c10c..b4d0bc2afa0 100644 --- a/go/vt/vttablet/tabletmanager/vreplication/framework_test.go +++ b/go/vt/vttablet/tabletmanager/vreplication/framework_test.go @@ -27,6 +27,8 @@ import ( "testing" "time" + "go.uber.org/goleak" + "vitess.io/vitess/go/vt/withddl" "vitess.io/vitess/go/vt/log" @@ -88,6 +90,7 @@ func init() { } func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) flag.Parse() // Do not remove this comment, import into google3 depends on it exitCode := func() int { diff --git a/go/vt/vttablet/tabletserver/vstreamer/main_flaky_test.go b/go/vt/vttablet/tabletserver/vstreamer/main_flaky_test.go index 11ad5426a66..ad77c601da5 100644 --- a/go/vt/vttablet/tabletserver/vstreamer/main_flaky_test.go +++ b/go/vt/vttablet/tabletserver/vstreamer/main_flaky_test.go @@ -23,6 +23,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/dbconfigs" @@ -38,6 +39,7 @@ var ( ) func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) flag.Parse() // Do not remove this comment, import into google3 depends on it ignoreKeyspaceShardInFieldAndRowEvents = true if testing.Short() { diff --git a/go/vt/withddl/withddl_test.go b/go/vt/withddl/withddl_test.go index b85c95b9613..2dfc5aedc1b 100644 --- a/go/vt/withddl/withddl_test.go +++ b/go/vt/withddl/withddl_test.go @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/sqltypes" @@ -275,6 +276,7 @@ func checkResult(t *testing.T, wantqr *sqltypes.Result, wanterr string, qr *sqlt } func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) flag.Parse() // Do not remove this comment, import into google3 depends on it tabletenv.Init() diff --git a/go/vt/wrangler/testlib/backup_test.go b/go/vt/wrangler/testlib/backup_test.go index d0f6476b31f..ae9b7e22037 100644 --- a/go/vt/wrangler/testlib/backup_test.go +++ b/go/vt/wrangler/testlib/backup_test.go @@ -423,6 +423,7 @@ func TestBackupRestoreLagged(t *testing.T) { }(ctx, sourceTablet) timer := time.NewTicker(1 * time.Second) + defer timer.Stop() <-timer.C sourceTablet.FakeMysqlDaemon.CurrentPrimaryPositionLocked(mysql.Position{ GTIDSet: mysql.MariadbGTIDSet{ @@ -435,6 +436,7 @@ func TestBackupRestoreLagged(t *testing.T) { }) timer2 := time.NewTicker(5 * time.Second) + defer timer2.Stop() select { case err := <-errCh: require.Nil(t, err) @@ -493,6 +495,7 @@ func TestBackupRestoreLagged(t *testing.T) { }(ctx, destTablet) timer = time.NewTicker(1 * time.Second) + defer timer.Stop() <-timer.C destTablet.FakeMysqlDaemon.CurrentPrimaryPositionLocked(mysql.Position{ GTIDSet: mysql.MariadbGTIDSet{ @@ -505,6 +508,7 @@ func TestBackupRestoreLagged(t *testing.T) { }) timer2 = time.NewTicker(5 * time.Second) + defer timer2.Stop() select { case err := <-errCh: require.Nil(t, err)