From 62d7b1b3787eef69e270ffca0800b986fb488fe8 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Mon, 10 Apr 2023 11:56:55 +0800 Subject: [PATCH] make TestGlobalAndLocalTSO stable Signed-off-by: Ryan Leung --- tests/integrations/client/client_test.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/integrations/client/client_test.go b/tests/integrations/client/client_test.go index e6cddc7eb1a8..4c68c4478e13 100644 --- a/tests/integrations/client/client_test.go +++ b/tests/integrations/client/client_test.go @@ -36,6 +36,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" pd "github.com/tikv/pd/client" + "github.com/tikv/pd/client/errs" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockid" "github.com/tikv/pd/pkg/storage/endpoint" @@ -453,13 +454,26 @@ func requestGlobalAndLocalTSO( var lastTS uint64 for i := 0; i < tsoRequestRound; i++ { globalPhysical1, globalLogical1, err := cli.GetTS(context.TODO()) - re.NoError(err) + // The allocator leader may be changed due to the environment issue. + if err != nil { + re.ErrorContains(err, errs.NotLeaderErr) + } else { + re.NoError(err) + } globalTS1 := tsoutil.ComposeTS(globalPhysical1, globalLogical1) localPhysical, localLogical, err := cli.GetLocalTS(context.TODO(), dc) - re.NoError(err) + if err != nil { + re.ErrorContains(err, errs.NotLeaderErr) + } else { + re.NoError(err) + } localTS := tsoutil.ComposeTS(localPhysical, localLogical) globalPhysical2, globalLogical2, err := cli.GetTS(context.TODO()) - re.NoError(err) + if err != nil { + re.ErrorContains(err, errs.NotLeaderErr) + } else { + re.NoError(err) + } globalTS2 := tsoutil.ComposeTS(globalPhysical2, globalLogical2) re.Less(lastTS, globalTS1) re.Less(globalTS1, localTS)