From f2eaf23e94d2ea267fb423a1058eab17ed5ab754 Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Thu, 16 Nov 2023 18:45:46 +0800 Subject: [PATCH] tests: make TestUpdateAfterResetTSO stable (#7385) close tikv/pd#7381 Signed-off-by: lhy1024 Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- pkg/member/member.go | 4 ++++ tests/integrations/tso/client_test.go | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/member/member.go b/pkg/member/member.go index 6eddf9a7c77..dd36214a595 100644 --- a/pkg/member/member.go +++ b/pkg/member/member.go @@ -27,6 +27,7 @@ import ( "time" "github.com/pingcap/errors" + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" "github.com/tikv/pd/pkg/election" @@ -181,6 +182,9 @@ func (m *EmbeddedEtcdMember) GetLastLeaderUpdatedTime() time.Time { // and make it become a PD leader. // leader should be changed when campaign leader frequently. func (m *EmbeddedEtcdMember) CampaignLeader(ctx context.Context, leaseTimeout int64) error { + failpoint.Inject("skipCampaignLeaderCheck", func() { + failpoint.Return(m.leadership.Campaign(leaseTimeout, m.MemberValue())) + }) if len(m.leadership.CampaignTimes) >= campaignLeaderFrequencyTimes { log.Warn("campaign times is too frequent, resign and campaign again", zap.String("leader-name", m.Name()), zap.String("leader-key", m.GetLeaderPath())) diff --git a/tests/integrations/tso/client_test.go b/tests/integrations/tso/client_test.go index 63243214e81..73198690966 100644 --- a/tests/integrations/tso/client_test.go +++ b/tests/integrations/tso/client_test.go @@ -300,7 +300,10 @@ func (suite *tsoClientTestSuite) TestUpdateAfterResetTSO() { re := suite.Require() ctx, cancel := context.WithCancel(suite.ctx) defer cancel() - + re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/member/skipCampaignLeaderCheck", "return(true)")) + defer func() { + re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/member/skipCampaignLeaderCheck")) + }() for i := 0; i < len(suite.clients); i++ { client := suite.clients[i] testutil.Eventually(re, func() bool {