Skip to content

Commit

Permalink
cp #7385 and #7402 to make test stable
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Feb 2, 2024
1 parent fa0213c commit cbb75bd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/member/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,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() {

Check failure on line 184 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / statics

undefined: failpoint

Check failure on line 184 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (10)

undefined: failpoint

Check failure on line 184 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (5)

undefined: failpoint

Check failure on line 184 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (1)

undefined: failpoint

Check failure on line 184 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (7)

undefined: failpoint

Check failure on line 184 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (3)

undefined: failpoint

Check failure on line 184 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (4)

undefined: failpoint

Check failure on line 184 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (2)

undefined: failpoint

Check failure on line 184 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (9)

undefined: failpoint

Check failure on line 184 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (8)

undefined: failpoint

Check failure on line 184 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / tso-function-test

undefined: failpoint
failpoint.Return(m.leadership.Campaign(leaseTimeout, m.MemberValue()))

Check failure on line 185 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / statics

undefined: failpoint

Check failure on line 185 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (10)

undefined: failpoint

Check failure on line 185 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (5)

undefined: failpoint

Check failure on line 185 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (1)

undefined: failpoint

Check failure on line 185 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (7)

undefined: failpoint

Check failure on line 185 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (3)

undefined: failpoint

Check failure on line 185 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (4)

undefined: failpoint

Check failure on line 185 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (2)

undefined: failpoint

Check failure on line 185 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (9)

undefined: failpoint

Check failure on line 185 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / chunks (8)

undefined: failpoint

Check failure on line 185 in pkg/member/member.go

View workflow job for this annotation

GitHub Actions / tso-function-test

undefined: failpoint
})
if m.leadership.GetCampaignTimesNum() >= campaignLeaderFrequencyTimes {
log.Warn("campaign times is too frequent, resign and campaign again",
zap.String("leader-name", m.Name()), zap.String("leader-key", m.GetLeaderPath()))
Expand Down
4 changes: 4 additions & 0 deletions tests/integrations/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ func TestLeaderTransfer(t *testing.T) {
cluster, err := tests.NewTestCluster(ctx, 2)
re.NoError(err)
defer cluster.Destroy()
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"))
}()

endpoints := runServer(re, cluster)
cli := setupCli(re, ctx, endpoints)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (suite *resourceManagerClientTestSuite) SetupSuite() {
re := suite.Require()

re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/mcs/resourcemanager/server/enableDegradedMode", `return(true)`))
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/member/skipCampaignLeaderCheck", "return(true)"))

suite.ctx, suite.clean = context.WithCancel(context.Background())

Expand Down Expand Up @@ -148,6 +149,7 @@ func (suite *resourceManagerClientTestSuite) TearDownSuite() {
suite.cluster.Destroy()
suite.clean()
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/mcs/resourcemanager/server/enableDegradedMode"))
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/member/skipCampaignLeaderCheck"))
}

func (suite *resourceManagerClientTestSuite) TearDownTest() {
Expand Down
5 changes: 5 additions & 0 deletions tests/integrations/mcs/tso/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ func (suite *APIServerForwardTestSuite) TestResignTSOPrimaryForward() {
defer tc.Destroy()
tc.WaitForDefaultPrimaryServing(re)

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 j := 0; j < 10; j++ {
tc.ResignPrimary(utils.DefaultKeyspaceID, utils.DefaultKeyspaceGroupID)
tc.WaitForDefaultPrimaryServing(re)
Expand Down
10 changes: 9 additions & 1 deletion tests/integrations/tso/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +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]
Expand Down Expand Up @@ -336,6 +340,11 @@ func (suite *tsoClientTestSuite) TestUpdateAfterResetTSO() {
func (suite *tsoClientTestSuite) TestRandomResignLeader() {
re := suite.Require()
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/tso/fastUpdatePhysicalInterval", "return(true)"))
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/member/skipCampaignLeaderCheck", "return(true)"))
defer func() {
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/tso/fastUpdatePhysicalInterval"))
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/member/skipCampaignLeaderCheck"))
}()

parallelAct := func() {
// After https://github.com/tikv/pd/issues/6376 is fixed, we can use a smaller number here.
Expand Down Expand Up @@ -373,7 +382,6 @@ func (suite *tsoClientTestSuite) TestRandomResignLeader() {
}

mcs.CheckMultiKeyspacesTSO(suite.ctx, re, suite.clients, parallelAct)
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/tso/fastUpdatePhysicalInterval"))
}

func (suite *tsoClientTestSuite) TestRandomShutdown() {
Expand Down

0 comments on commit cbb75bd

Please sign in to comment.