diff --git a/client/client_test.go b/client/client_test.go index 305d054fa18..02fdd4621f3 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -48,17 +48,19 @@ func TestClientCtx(t *testing.T) { start := time.Now() ctx, cancel := context.WithTimeout(context.TODO(), time.Second*3) defer cancel() - _, err := NewClientWithContext(ctx, caller.TestComponent, + cli, err := NewClientWithContext(ctx, caller.TestComponent, []string{testClientURL}, SecurityOption{}) re.Error(err) + defer cli.Close() re.Less(time.Since(start), time.Second*5) } func TestClientWithRetry(t *testing.T) { re := require.New(t) start := time.Now() - _, err := NewClientWithContext(context.TODO(), caller.TestComponent, + cli, err := NewClientWithContext(context.TODO(), caller.TestComponent, []string{testClientURL}, SecurityOption{}, opt.WithMaxErrorRetry(5)) re.Error(err) + defer cli.Close() re.Less(time.Since(start), time.Second*10) } diff --git a/tests/integrations/client/client_test.go b/tests/integrations/client/client_test.go index 9cfad7a1a6b..e042c969dfe 100644 --- a/tests/integrations/client/client_test.go +++ b/tests/integrations/client/client_test.go @@ -1910,6 +1910,7 @@ func TestGetRegionWithBackoff(t *testing.T) { // Initialize the client with context and backoff client, err := pd.NewClientWithContext(ctx, caller.TestComponent, endpoints, pd.SecurityOption{}) re.NoError(err) + defer client.Close() // Record the start time start := time.Now() diff --git a/tests/integrations/mcs/tso/keyspace_group_manager_test.go b/tests/integrations/mcs/tso/keyspace_group_manager_test.go index 5326a954f84..87d1b46d5a0 100644 --- a/tests/integrations/mcs/tso/keyspace_group_manager_test.go +++ b/tests/integrations/mcs/tso/keyspace_group_manager_test.go @@ -464,6 +464,7 @@ func (suite *tsoKeyspaceGroupManagerTestSuite) dispatchClient( wg.Add(1) go func() { defer wg.Done() + defer tsoClient.Close() for { select { case <-ctx.Done(): diff --git a/tests/integrations/realcluster/cluster_id_test.go b/tests/integrations/realcluster/cluster_id_test.go index 0e113e79015..0a324de582c 100644 --- a/tests/integrations/realcluster/cluster_id_test.go +++ b/tests/integrations/realcluster/cluster_id_test.go @@ -53,10 +53,11 @@ func (s *clusterIDSuite) TestClientClusterID() { pdEndpoints := getPDEndpoints(re) // Try to create a client with the mixed endpoints. - _, err := pd.NewClientWithContext( + cli, err := pd.NewClientWithContext( ctx, caller.TestComponent, pdEndpoints, pd.SecurityOption{}, opt.WithMaxErrorRetry(1), ) re.Error(err) + defer cli.Close() re.Contains(err.Error(), "unmatched cluster id") } diff --git a/tests/integrations/realcluster/reboot_pd_test.go b/tests/integrations/realcluster/reboot_pd_test.go index 018ee7f74a5..4120c99a9de 100644 --- a/tests/integrations/realcluster/reboot_pd_test.go +++ b/tests/integrations/realcluster/reboot_pd_test.go @@ -41,6 +41,7 @@ func (s *rebootPDSuite) TestReloadLabel() { ctx := context.Background() pdHTTPCli := http.NewClient("pd-real-cluster-test", getPDEndpoints(re)) + defer pdHTTPCli.Close() resp, err := pdHTTPCli.GetStores(ctx) re.NoError(err) re.NotEmpty(resp.Stores) diff --git a/tests/integrations/realcluster/scheduler_test.go b/tests/integrations/realcluster/scheduler_test.go index 0ef51f45df6..3df7226bcd6 100644 --- a/tests/integrations/realcluster/scheduler_test.go +++ b/tests/integrations/realcluster/scheduler_test.go @@ -52,6 +52,7 @@ func (s *schedulerSuite) TestTransferLeader() { defer cancel() pdHTTPCli := http.NewClient("pd-real-cluster-test", getPDEndpoints(re)) + defer pdHTTPCli.Close() resp, err := pdHTTPCli.GetLeader(ctx) re.NoError(err) oldLeader := resp.Name @@ -102,6 +103,7 @@ func (s *schedulerSuite) TestRegionLabelDenyScheduler() { defer cancel() pdHTTPCli := http.NewClient("pd-real-cluster-test", getPDEndpoints(re)) + defer pdHTTPCli.Close() regions, err := pdHTTPCli.GetRegions(ctx) re.NoError(err) re.NotEmpty(regions.Regions) @@ -211,6 +213,7 @@ func (s *schedulerSuite) TestGrantOrEvictLeaderTwice() { defer cancel() pdHTTPCli := http.NewClient("pd-real-cluster-test", getPDEndpoints(re)) + defer pdHTTPCli.Close() regions, err := pdHTTPCli.GetRegions(ctx) re.NoError(err) re.NotEmpty(regions.Regions) diff --git a/tests/server/api/api_test.go b/tests/server/api/api_test.go index e99ff151490..90ef784e75a 100644 --- a/tests/server/api/api_test.go +++ b/tests/server/api/api_test.go @@ -945,9 +945,9 @@ func TestRemovingProgress(t *testing.T) { // store 2: (30-10)/(30+40) ~= 0.285 re.Equal("0.29", fmt.Sprintf("%.2f", p.Progress)) // store 2: 20/10s = 2 - re.LessOrEqual(2.0, p.CurrentSpeed) + re.LessOrEqual(p.CurrentSpeed, 2.0) // store 2: (10+40)/2 = 25s - re.GreaterOrEqual(25.0, p.LeftSeconds) + re.GreaterOrEqual(p.LeftSeconds, 25.0) re.NoError(failpoint.Disable("github.com/tikv/pd/server/cluster/highFrequencyClusterJobs")) } @@ -1150,8 +1150,8 @@ func TestPreparingProgress(t *testing.T) { re.NoError(json.Unmarshal(output, &p)) re.Equal("preparing", p.Action) re.Equal("0.05", fmt.Sprintf("%.2f", p.Progress)) - re.LessOrEqual(1.0, p.CurrentSpeed) - re.GreaterOrEqual(179.0, p.LeftSeconds) + re.LessOrEqual(p.CurrentSpeed, 1.0) + re.GreaterOrEqual(p.LeftSeconds, 179.0) re.NoError(failpoint.Disable("github.com/tikv/pd/server/cluster/highFrequencyClusterJobs")) }