diff --git a/client/http/client_test.go b/client/http/client_test.go index 8769fa53f9ae..59de90bab6cc 100644 --- a/client/http/client_test.go +++ b/client/http/client_test.go @@ -24,9 +24,15 @@ import ( "github.com/stretchr/testify/require" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/retry" + "github.com/tikv/pd/client/testutil" "go.uber.org/atomic" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + func TestPDAllowFollowerHandleHeader(t *testing.T) { re := require.New(t) checked := 0 diff --git a/client/resource_group/controller/controller_test.go b/client/resource_group/controller/controller_test.go index a59be4d5a2de..65abb450b1b4 100644 --- a/client/resource_group/controller/controller_test.go +++ b/client/resource_group/controller/controller_test.go @@ -31,8 +31,14 @@ import ( "github.com/stretchr/testify/require" pd "github.com/tikv/pd/client" "github.com/tikv/pd/client/errs" + "github.com/tikv/pd/client/testutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + func createTestGroupCostController(re *require.Assertions) *groupCostController { group := &rmpb.ResourceGroup{ Name: "test", diff --git a/pkg/balancer/balancer_test.go b/pkg/balancer/balancer_test.go index 2c760c6220c3..81fba0e18b9d 100644 --- a/pkg/balancer/balancer_test.go +++ b/pkg/balancer/balancer_test.go @@ -19,8 +19,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/testutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + func TestBalancerPutAndDelete(t *testing.T) { re := require.New(t) balancers := []Balancer[uint32]{ diff --git a/pkg/core/factory_test.go b/pkg/core/factory_test.go index 9f0ba8838857..8b0216852c6b 100644 --- a/pkg/core/factory_test.go +++ b/pkg/core/factory_test.go @@ -19,9 +19,15 @@ import ( "github.com/gogo/protobuf/proto" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/pkg/utils/typeutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + func BenchmarkDeepClone(b *testing.B) { for i := 0; i < b.N; i++ { src := &metapb.Region{Id: 1} diff --git a/pkg/core/rangetree/range_tree_test.go b/pkg/core/rangetree/range_tree_test.go index 6955947cb1bc..e76e43dfb5ed 100644 --- a/pkg/core/rangetree/range_tree_test.go +++ b/pkg/core/rangetree/range_tree_test.go @@ -19,8 +19,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/testutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + type simpleBucketItem struct { startKey []byte endKey []byte diff --git a/pkg/core/storelimit/limit_test.go b/pkg/core/storelimit/limit_test.go index e11618767a12..a041e15d6b78 100644 --- a/pkg/core/storelimit/limit_test.go +++ b/pkg/core/storelimit/limit_test.go @@ -24,8 +24,14 @@ import ( "github.com/stretchr/testify/require" "github.com/tikv/pd/pkg/core/constant" + "github.com/tikv/pd/pkg/utils/testutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + func TestStoreLimit(t *testing.T) { re := require.New(t) rate := int64(15) diff --git a/pkg/id/id_test.go b/pkg/id/id_test.go index 94f0670b9792..5e2e15cf2c98 100644 --- a/pkg/id/id_test.go +++ b/pkg/id/id_test.go @@ -22,8 +22,14 @@ import ( "github.com/stretchr/testify/require" "github.com/tikv/pd/pkg/utils/etcdutil" + "github.com/tikv/pd/pkg/utils/testutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + const ( rootPath = "/pd" leaderPath = "/pd/leader" diff --git a/pkg/keyspace/keyspace_test.go b/pkg/keyspace/keyspace_test.go index 4bd8dfd54744..1d9601f44923 100644 --- a/pkg/keyspace/keyspace_test.go +++ b/pkg/keyspace/keyspace_test.go @@ -32,9 +32,15 @@ import ( "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/etcdutil" + "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/pkg/utils/typeutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + const ( testConfig = "test config" testConfig1 = "config_entry_1" diff --git a/pkg/ratelimit/concurrency_limiter_test.go b/pkg/ratelimit/concurrency_limiter_test.go index f0af1125d21b..aa3bfa053515 100644 --- a/pkg/ratelimit/concurrency_limiter_test.go +++ b/pkg/ratelimit/concurrency_limiter_test.go @@ -23,8 +23,14 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/testutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + func TestConcurrencyLimiter(t *testing.T) { re := require.New(t) cl := NewConcurrencyLimiter(10) diff --git a/pkg/schedule/config/store_config_test.go b/pkg/schedule/config/store_config_test.go index 3f4789a74c96..f47a4b8f477a 100644 --- a/pkg/schedule/config/store_config_test.go +++ b/pkg/schedule/config/store_config_test.go @@ -18,8 +18,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/testutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + func TestMergeCheck(t *testing.T) { re := require.New(t) testdata := []struct { diff --git a/pkg/schedule/filter/candidates_test.go b/pkg/schedule/filter/candidates_test.go index 0d805312ba78..9e068a0fd5c9 100644 --- a/pkg/schedule/filter/candidates_test.go +++ b/pkg/schedule/filter/candidates_test.go @@ -22,8 +22,14 @@ import ( "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/schedule/config" "github.com/tikv/pd/pkg/schedule/plan" + "github.com/tikv/pd/pkg/utils/testutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + // A dummy comparer for testing. func idComparer(a, b *core.StoreInfo) int { if a.GetID() > b.GetID() { diff --git a/pkg/schedule/labeler/labeler_test.go b/pkg/schedule/labeler/labeler_test.go index bd51bab7d83b..b48a72d497c5 100644 --- a/pkg/schedule/labeler/labeler_test.go +++ b/pkg/schedule/labeler/labeler_test.go @@ -32,8 +32,13 @@ import ( "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/testutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + func TestAdjustRule(t *testing.T) { re := require.New(t) rule := LabelRule{ @@ -95,7 +100,9 @@ func TestAdjustRule2(t *testing.T) { func TestGetSetRule(t *testing.T) { re := require.New(t) store := endpoint.NewStorageEndpoint(kv.NewMemoryKV(), nil) - labeler, err := NewRegionLabeler(context.Background(), store, time.Millisecond*10) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + labeler, err := NewRegionLabeler(ctx, store, time.Millisecond*10) re.NoError(err) rules := []*LabelRule{ {ID: "rule1", Labels: []RegionLabel{{Key: "k1", Value: "v1"}}, RuleType: "key-range", Data: MakeKeyRanges("1234", "5678")}, @@ -148,7 +155,9 @@ func TestTxnWithEtcd(t *testing.T) { _, client, clean := etcdutil.NewTestEtcdCluster(t, 1) defer clean() store := storage.NewStorageWithEtcdBackend(client, "") - labeler, err := NewRegionLabeler(context.Background(), store, time.Millisecond*10) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + labeler, err := NewRegionLabeler(ctx, store, time.Millisecond*10) re.NoError(err) // test patch rules in batch rulesNum := 200 @@ -213,7 +222,9 @@ func TestTxnWithEtcd(t *testing.T) { func TestIndex(t *testing.T) { re := require.New(t) store := endpoint.NewStorageEndpoint(kv.NewMemoryKV(), nil) - labeler, err := NewRegionLabeler(context.Background(), store, time.Millisecond*10) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + labeler, err := NewRegionLabeler(ctx, store, time.Millisecond*10) re.NoError(err) rules := []*LabelRule{ {ID: "rule0", Labels: []RegionLabel{{Key: "k1", Value: "v0"}}, RuleType: "key-range", Data: MakeKeyRanges("", "")}, @@ -255,7 +266,9 @@ func TestIndex(t *testing.T) { func TestSaveLoadRule(t *testing.T) { re := require.New(t) store := endpoint.NewStorageEndpoint(kv.NewMemoryKV(), nil) - labeler, err := NewRegionLabeler(context.Background(), store, time.Millisecond*10) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + labeler, err := NewRegionLabeler(ctx, store, time.Millisecond*10) re.NoError(err) rules := []*LabelRule{ {ID: "rule1", Labels: []RegionLabel{{Key: "k1", Value: "v1"}}, RuleType: "key-range", Data: MakeKeyRanges("1234", "5678")}, @@ -266,8 +279,9 @@ func TestSaveLoadRule(t *testing.T) { err := labeler.SetLabelRule(r) re.NoError(err) } - - labeler, err = NewRegionLabeler(context.Background(), store, time.Millisecond*100) + ctx1, cancel1 := context.WithCancel(context.Background()) + defer cancel1() + labeler, err = NewRegionLabeler(ctx1, store, time.Millisecond*100) re.NoError(err) for _, r := range rules { r2 := labeler.GetLabelRule(r.ID) @@ -300,7 +314,9 @@ func expectSameRules(re *require.Assertions, r1, r2 *LabelRule) { func TestKeyRange(t *testing.T) { re := require.New(t) store := endpoint.NewStorageEndpoint(kv.NewMemoryKV(), nil) - labeler, err := NewRegionLabeler(context.Background(), store, time.Millisecond*10) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + labeler, err := NewRegionLabeler(ctx, store, time.Millisecond*10) re.NoError(err) rules := []*LabelRule{ {ID: "rule1", Labels: []RegionLabel{{Key: "k1", Value: "v1"}}, RuleType: "key-range", Data: MakeKeyRanges("1234", "5678")}, @@ -341,7 +357,9 @@ func TestKeyRange(t *testing.T) { func TestLabelerRuleTTL(t *testing.T) { re := require.New(t) store := endpoint.NewStorageEndpoint(kv.NewMemoryKV(), nil) - labeler, err := NewRegionLabeler(context.Background(), store, time.Millisecond*10) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + labeler, err := NewRegionLabeler(ctx, store, time.Millisecond*10) re.NoError(err) rules := []*LabelRule{ { @@ -416,7 +434,9 @@ func TestGC(t *testing.T) { re := require.New(t) // set gcInterval to 1 hour. store := endpoint.NewStorageEndpoint(kv.NewMemoryKV(), nil) - labeler, err := NewRegionLabeler(context.Background(), store, time.Hour) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + labeler, err := NewRegionLabeler(ctx, store, time.Hour) re.NoError(err) ttls := []string{"1ms", "1ms", "1ms", "5ms", "5ms", "10ms", "1h", "24h"} start, _ := hex.DecodeString("1234") diff --git a/pkg/schedule/operator/builder_test.go b/pkg/schedule/operator/builder_test.go index b010dcf935b4..5a5d6719b839 100644 --- a/pkg/schedule/operator/builder_test.go +++ b/pkg/schedule/operator/builder_test.go @@ -25,8 +25,14 @@ import ( "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" "github.com/tikv/pd/pkg/schedule/config" + "github.com/tikv/pd/pkg/utils/testutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + type operatorBuilderTestSuite struct { suite.Suite diff --git a/pkg/schedule/operator/step_test.go b/pkg/schedule/operator/step_test.go index 014703d00f99..91dc2abea0e9 100644 --- a/pkg/schedule/operator/step_test.go +++ b/pkg/schedule/operator/step_test.go @@ -29,6 +29,7 @@ import ( type operatorStepTestSuite struct { suite.Suite + cancel context.CancelFunc cluster *mockcluster.Cluster } @@ -44,7 +45,9 @@ type testCase struct { } func (suite *operatorStepTestSuite) SetupTest() { - suite.cluster = mockcluster.NewCluster(context.Background(), mockconfig.NewTestOptions()) + ctx, cancel := context.WithCancel(context.Background()) + suite.cancel = cancel + suite.cluster = mockcluster.NewCluster(ctx, mockconfig.NewTestOptions()) for i := 1; i <= 10; i++ { suite.cluster.PutStoreWithLabels(uint64(i)) } @@ -53,6 +56,12 @@ func (suite *operatorStepTestSuite) SetupTest() { suite.cluster.SetStoreDown(10) } +func (suite *operatorStepTestSuite) TearDownTest() { + if suite.cancel != nil { + suite.cancel() + } +} + func (suite *operatorStepTestSuite) TestTransferLeader() { re := suite.Require() step := TransferLeader{FromStore: 1, ToStore: 2} diff --git a/pkg/schedule/placement/config_test.go b/pkg/schedule/placement/config_test.go index ccee88373318..24617c8b4631 100644 --- a/pkg/schedule/placement/config_test.go +++ b/pkg/schedule/placement/config_test.go @@ -18,8 +18,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/testutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + func TestTrim(t *testing.T) { re := require.New(t) rc := newRuleConfig() diff --git a/pkg/schedule/plan/balance_plan_test.go b/pkg/schedule/plan/balance_plan_test.go index 59f2acc689a7..c4755639ea4a 100644 --- a/pkg/schedule/plan/balance_plan_test.go +++ b/pkg/schedule/plan/balance_plan_test.go @@ -21,8 +21,14 @@ import ( "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/suite" "github.com/tikv/pd/pkg/core" + "github.com/tikv/pd/pkg/utils/testutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + type balanceSchedulerPlanAnalyzeTestSuite struct { suite.Suite diff --git a/pkg/schedule/rangelist/range_list_test.go b/pkg/schedule/rangelist/range_list_test.go index 5baa7f16f286..208e22df8a03 100644 --- a/pkg/schedule/rangelist/range_list_test.go +++ b/pkg/schedule/rangelist/range_list_test.go @@ -18,8 +18,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/testutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + func TestRangeList(t *testing.T) { re := require.New(t) rl := NewBuilder().Build() diff --git a/pkg/schedule/scatter/region_scatterer_test.go b/pkg/schedule/scatter/region_scatterer_test.go index 4b31e81aacb5..e4a4e7af5cbe 100644 --- a/pkg/schedule/scatter/region_scatterer_test.go +++ b/pkg/schedule/scatter/region_scatterer_test.go @@ -33,9 +33,15 @@ import ( "github.com/tikv/pd/pkg/schedule/hbstream" "github.com/tikv/pd/pkg/schedule/operator" "github.com/tikv/pd/pkg/schedule/placement" + "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/pkg/versioninfo" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + type sequencer struct { minID uint64 maxID uint64 diff --git a/pkg/schedule/schedulers/balance_leader_test.go b/pkg/schedule/schedulers/balance_leader_test.go index 44ad1f2c0a54..9271aa8bba8a 100644 --- a/pkg/schedule/schedulers/balance_leader_test.go +++ b/pkg/schedule/schedulers/balance_leader_test.go @@ -21,8 +21,14 @@ import ( "github.com/stretchr/testify/require" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" + "github.com/tikv/pd/pkg/utils/testutil" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + func TestBalanceLeaderSchedulerConfigClone(t *testing.T) { re := require.New(t) keyRanges1, _ := getKeyRanges([]string{"a", "b", "c", "d"}) diff --git a/pkg/utils/apiutil/serverapi/middleware.go b/pkg/utils/apiutil/serverapi/middleware.go index 9af8d234b346..0f93ce8f3010 100644 --- a/pkg/utils/apiutil/serverapi/middleware.go +++ b/pkg/utils/apiutil/serverapi/middleware.go @@ -46,7 +46,6 @@ func (h *runtimeServiceValidator) ServeHTTP(w http.ResponseWriter, r *http.Reque next(w, r) return } - http.Error(w, "no service", http.StatusServiceUnavailable) } diff --git a/pkg/utils/testutil/leak.go b/pkg/utils/testutil/leak.go index ba2ebb7fcb03..43d3df150bae 100644 --- a/pkg/utils/testutil/leak.go +++ b/pkg/utils/testutil/leak.go @@ -26,7 +26,6 @@ var LeakOptions = []goleak.Option{ goleak.IgnoreTopFunction("sync.runtime_notifyListWait"), // TODO: remove the below options once we fixed the http connection leak problems goleak.IgnoreTopFunction("internal/poll.runtime_pollWait"), - goleak.IgnoreTopFunction("net/http.(*persistConn).writeLoop"), // natefinch/lumberjack#56, It's a goroutine leak bug. Another ignore option PR https://github.com/pingcap/tidb/pull/27405/ goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).millRun"), } diff --git a/tests/compatibility/version_upgrade_test.go b/tests/compatibility/version_upgrade_test.go index 27eb07b0da27..d9e031b746b6 100644 --- a/tests/compatibility/version_upgrade_test.go +++ b/tests/compatibility/version_upgrade_test.go @@ -23,10 +23,16 @@ import ( "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/server" "github.com/tikv/pd/tests" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + func TestStoreRegister(t *testing.T) { re := require.New(t) ctx, cancel := context.WithCancel(context.Background()) diff --git a/tests/integrations/mcs/scheduling/api_test.go b/tests/integrations/mcs/scheduling/api_test.go index eba94213d7e4..45e16952c8bb 100644 --- a/tests/integrations/mcs/scheduling/api_test.go +++ b/tests/integrations/mcs/scheduling/api_test.go @@ -607,6 +607,8 @@ func (suite *apiTestSuite) TestStores() { func (suite *apiTestSuite) checkStores(cluster *tests.TestCluster) { re := suite.Require() + // prevent the offline store from changing to tombstone + tests.MustPutRegion(re, cluster, 3, 6, []byte("a"), []byte("b")) stores := []*metapb.Store{ { // metapb.StoreState_Up == 0 diff --git a/tests/integrations/tso/client_test.go b/tests/integrations/tso/client_test.go index bb721e6c5dda..1b2d9f5971b8 100644 --- a/tests/integrations/tso/client_test.go +++ b/tests/integrations/tso/client_test.go @@ -40,8 +40,13 @@ import ( "github.com/tikv/pd/tests" "github.com/tikv/pd/tests/integrations/mcs" handlersutil "github.com/tikv/pd/tests/server/apiv2/handlers" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + var r = rand.New(rand.NewSource(time.Now().UnixNano())) type tsoClientTestSuite struct { diff --git a/tests/server/api/api_test.go b/tests/server/api/api_test.go index 31769d91ffc0..d60b4f03949f 100644 --- a/tests/server/api/api_test.go +++ b/tests/server/api/api_test.go @@ -53,7 +53,7 @@ func TestReconnect(t *testing.T) { defer cancel() cluster, err := tests.NewTestCluster(ctx, 3, func(conf *config.Config, _ string) { conf.TickInterval = typeutil.Duration{Duration: 50 * time.Millisecond} - conf.ElectionInterval = typeutil.Duration{Duration: 250 * time.Millisecond} + conf.ElectionInterval = typeutil.Duration{Duration: 300 * time.Millisecond} }) re.NoError(err) defer cluster.Destroy() diff --git a/tests/server/cluster/cluster_test.go b/tests/server/cluster/cluster_test.go index c95aa50cb3dd..bbcc0f2a48e4 100644 --- a/tests/server/cluster/cluster_test.go +++ b/tests/server/cluster/cluster_test.go @@ -52,10 +52,15 @@ import ( "github.com/tikv/pd/server/config" "github.com/tikv/pd/tests" "github.com/tikv/pd/tests/server/api" + "go.uber.org/goleak" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + const ( initEpochVersion uint64 = 1 initEpochConfVer uint64 = 1 diff --git a/tests/server/config/config_test.go b/tests/server/config/config_test.go index d225614fa96b..098e5dfb6779 100644 --- a/tests/server/config/config_test.go +++ b/tests/server/config/config_test.go @@ -34,8 +34,13 @@ import ( "github.com/tikv/pd/pkg/versioninfo" "github.com/tikv/pd/server/config" "github.com/tikv/pd/tests" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, tu.LeakOptions...) +} + func TestRateLimitConfigReload(t *testing.T) { re := require.New(t) ctx, cancel := context.WithCancel(context.Background()) diff --git a/tests/server/join/join_fail/join_fail_test.go b/tests/server/join/join_fail/join_fail_test.go index 0e3762810707..1564d41599ff 100644 --- a/tests/server/join/join_fail/join_fail_test.go +++ b/tests/server/join/join_fail/join_fail_test.go @@ -20,9 +20,15 @@ import ( "github.com/pingcap/failpoint" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/tests" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + func TestFailedPDJoinInStep1(t *testing.T) { re := require.New(t) ctx, cancel := context.WithCancel(context.Background()) diff --git a/tests/server/keyspace/keyspace_test.go b/tests/server/keyspace/keyspace_test.go index d6e188359ce2..659992f0a358 100644 --- a/tests/server/keyspace/keyspace_test.go +++ b/tests/server/keyspace/keyspace_test.go @@ -30,10 +30,16 @@ import ( "github.com/tikv/pd/pkg/keyspace" "github.com/tikv/pd/pkg/schedule/labeler" "github.com/tikv/pd/pkg/storage/endpoint" + "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/server/config" "github.com/tikv/pd/tests" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + type keyspaceTestSuite struct { suite.Suite cancel context.CancelFunc diff --git a/tests/server/storage/hot_region_storage_test.go b/tests/server/storage/hot_region_storage_test.go index 2eccb4b28e96..2bc81471f112 100644 --- a/tests/server/storage/hot_region_storage_test.go +++ b/tests/server/storage/hot_region_storage_test.go @@ -29,8 +29,13 @@ import ( "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/server/config" "github.com/tikv/pd/tests" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + func TestHotRegionStorage(t *testing.T) { re := require.New(t) statistics.Denoising = false diff --git a/tools/go.mod b/tools/go.mod index aef95dfa6608..a087e6fed818 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -34,7 +34,6 @@ require ( github.com/tikv/pd/client v0.0.0-00010101000000-000000000000 go.etcd.io/etcd v0.5.0-alpha.5.0.20240320135013-950cd5fbe6ca go.uber.org/automaxprocs v1.5.3 - go.uber.org/goleak v1.3.0 go.uber.org/zap v1.27.0 golang.org/x/text v0.16.0 golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d @@ -163,6 +162,7 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/dig v1.9.0 // indirect go.uber.org/fx v1.12.0 // indirect + go.uber.org/goleak v1.3.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/arch v0.3.0 // indirect golang.org/x/crypto v0.23.0 // indirect diff --git a/tools/pd-backup/pdbackup/backup_test.go b/tools/pd-backup/pdbackup/backup_test.go index b67873baf8e8..0c40c3847ab8 100644 --- a/tools/pd-backup/pdbackup/backup_test.go +++ b/tools/pd-backup/pdbackup/backup_test.go @@ -19,12 +19,10 @@ import ( sc "github.com/tikv/pd/pkg/schedule/config" "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/utils/etcdutil" - "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/pkg/utils/typeutil" "github.com/tikv/pd/server/config" "go.etcd.io/etcd/clientv3" "go.etcd.io/etcd/embed" - "go.uber.org/goleak" ) var ( @@ -33,10 +31,6 @@ var ( allocTimestampMax = uint64(1257894000) ) -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m, testutil.LeakOptions...) -} - type backupTestSuite struct { suite.Suite