From 9f2ccf272e0ccdd71f7f026d35b1c18c47eb7073 Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Wed, 22 Nov 2023 02:30:56 +0800 Subject: [PATCH] tests: make TestFallbackTSOConsistency stable Signed-off-by: lhy1024 --- tests/integrations/tso/consistency_test.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/integrations/tso/consistency_test.go b/tests/integrations/tso/consistency_test.go index 1d35e8bf5e2..74f5090bf3b 100644 --- a/tests/integrations/tso/consistency_test.go +++ b/tests/integrations/tso/consistency_test.go @@ -27,7 +27,7 @@ import ( tso "github.com/tikv/pd/pkg/mcs/tso/server" tsopkg "github.com/tikv/pd/pkg/tso" "github.com/tikv/pd/pkg/utils/tempurl" - pd "github.com/tikv/pd/pkg/utils/testutil" + tu "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/pkg/utils/tsoutil" "github.com/tikv/pd/tests" "google.golang.org/grpc" @@ -82,7 +82,7 @@ func (suite *tsoConsistencyTestSuite) SetupSuite() { suite.pdLeaderServer = suite.cluster.GetServer(leaderName) backendEndpoints := suite.pdLeaderServer.GetAddr() if suite.legacy { - suite.pdClient = pd.MustNewGrpcClient(re, backendEndpoints) + suite.pdClient = tu.MustNewGrpcClient(re, backendEndpoints) } else { suite.tsoServer, suite.tsoServerCleanup = tests.StartSingleTSOTestServer(suite.ctx, re, backendEndpoints, tempurl.Alloc()) suite.tsoClientConn, suite.tsoClient = tso.MustNewGrpcClient(re, suite.tsoServer.GetAddr()) @@ -127,12 +127,15 @@ func (suite *tsoConsistencyTestSuite) request(ctx context.Context, count uint32) DcLocation: tsopkg.GlobalDCLocation, Count: count, } - tsoClient, err := suite.tsoClient.Tso(ctx) - re.NoError(err) - defer tsoClient.CloseSend() - re.NoError(tsoClient.Send(req)) - resp, err := tsoClient.Recv() - re.NoError(err) + var resp *tsopb.TsoResponse + tu.Eventually(re, func() bool { + tsoClient, err := suite.tsoClient.Tso(ctx) + re.NoError(err) + defer tsoClient.CloseSend() + re.NoError(tsoClient.Send(req)) + resp, err = tsoClient.Recv() + return err == nil && resp != nil + }) return checkAndReturnTimestampResponse(re, resp) }