diff --git a/client/http/client_test.go b/client/http/client_test.go index 5d63a34df54..39f00a62f89 100644 --- a/client/http/client_test.go +++ b/client/http/client_test.go @@ -25,8 +25,14 @@ 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/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 a59be4d5a2d..65abb450b1b 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 2c760c6220c..81fba0e18b9 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 9f0ba883885..8b0216852c6 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 6955947cb1b..e76e43dfb5e 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 e11618767a1..a041e15d6b7 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 94f0670b979..5e2e15cf2c9 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 b322def6bad..5e085e5fa4f 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 f0af1125d21..aa3bfa05351 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 3f4789a74c9..f47a4b8f477 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 0d805312ba7..9e068a0fd5c 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 bd51bab7d83..b48a72d497c 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 b010dcf935b..5a5d6719b83 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 014703d00f9..91dc2abea0e 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 ccee8837331..24617c8b463 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 59f2acc689a..c4755639ea4 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 5baa7f16f28..208e22df8a0 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 4b31e81aacb..e4a4e7af5cb 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 eb1d8a539ce..b3177ef41d4 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 23723d9b254..b905fda7bb5 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/tests/compatibility/version_upgrade_test.go b/tests/compatibility/version_upgrade_test.go index 27eb07b0da2..d9e031b746b 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 6335d104e3e..e183eaf25d6 100644 --- a/tests/integrations/mcs/scheduling/api_test.go +++ b/tests/integrations/mcs/scheduling/api_test.go @@ -610,6 +610,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 a669e093200..b0c1cdcb04d 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 8d48221784a..591c2364d43 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 a1a7f68646e..f7f908e7993 100644 --- a/tests/server/cluster/cluster_test.go +++ b/tests/server/cluster/cluster_test.go @@ -53,10 +53,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 d225614fa96..098e5dfb677 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 0e376281070..1564d41599f 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 d6e188359ce..659992f0a35 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 2eccb4b28e9..2bc81471f11 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 a9bc5446477..558ae907d5c 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -36,7 +36,6 @@ require ( go.etcd.io/etcd/pkg/v3 v3.5.15 go.etcd.io/etcd/server/v3 v3.5.15 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 @@ -181,6 +180,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.7.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 8124763551b..ba0c61ee174 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/utils/etcdutil" "github.com/tikv/pd/pkg/utils/keypath" - "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/pkg/utils/typeutil" "github.com/tikv/pd/server/config" clientv3 "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/server/v3/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