Skip to content

Commit

Permalink
tests: unify frequency check time to make test stable (tikv#8556)
Browse files Browse the repository at this point in the history
close tikv#8555

tests: unify frequency check time to make test stable

Signed-off-by: husharp <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
HuSharp and ti-chi-bot[bot] authored Aug 22, 2024
1 parent 32829f1 commit 8e45f9e
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 23 deletions.
8 changes: 1 addition & 7 deletions pkg/member/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,7 @@ func (m *EmbeddedEtcdMember) CampaignLeader(ctx context.Context, leaseTimeout in
failpoint.Return(m.leadership.Campaign(leaseTimeout, m.MemberValue()))
})

checkTimes := campaignLeaderFrequencyTimes
failpoint.Inject("changeFrequencyTimes", func(val failpoint.Value) {
if v, ok := val.(int); ok {
checkTimes = v
}
})
if m.leadership.GetCampaignTimesNum() > checkTimes {
if m.leadership.GetCampaignTimesNum() > campaignLeaderFrequencyTimes {
if err := m.ResignEtcdLeader(ctx, m.Name(), ""); err != nil {
return err
}
Expand Down
8 changes: 2 additions & 6 deletions tests/integrations/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,15 @@ func TestClientLeaderChange(t *testing.T) {

func TestLeaderTransferAndMoveCluster(t *testing.T) {
re := require.New(t)
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/member/changeFrequencyTimes", "return(10)"))
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/changeFrequencyTimes"))
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/member/skipCampaignLeaderCheck"))
}()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cluster, err := tests.NewTestCluster(ctx, 3)
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(ctx, re, endpoints)
Expand Down
4 changes: 4 additions & 0 deletions tests/integrations/client/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"time"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
Expand Down Expand Up @@ -71,6 +72,7 @@ func TestHTTPClientTestSuiteWithServiceDiscovery(t *testing.T) {

func (suite *httpClientTestSuite) SetupSuite() {
re := suite.Require()
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/member/skipCampaignLeaderCheck", "return(true)"))
suite.ctx, suite.cancelFunc = context.WithCancel(context.Background())

cluster, err := tests.NewTestCluster(suite.ctx, 2)
Expand Down Expand Up @@ -125,6 +127,8 @@ func (suite *httpClientTestSuite) SetupSuite() {
}

func (suite *httpClientTestSuite) TearDownSuite() {
re := suite.Require()
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/member/skipCampaignLeaderCheck"))
suite.cancelFunc()
suite.client.Close()
suite.cluster.Destroy()
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/mcs/scheduling/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,9 @@ func (suite *multipleServerTestSuite) TearDownSuite() {

func (suite *multipleServerTestSuite) TestReElectLeader() {
re := suite.Require()
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/member/changeFrequencyTimes", "return(10)"))
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/changeFrequencyTimes"))
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/member/skipCampaignLeaderCheck"))
}()
tc, err := tests.NewTestSchedulingCluster(suite.ctx, 1, suite.backendEndpoints)
re.NoError(err)
Expand Down
8 changes: 4 additions & 4 deletions tests/server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ func TestDamagedRegion(t *testing.T) {

func TestRegionStatistics(t *testing.T) {
re := require.New(t)
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/member/changeFrequencyTimes", "return(10)"))
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/changeFrequencyTimes"))
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/member/skipCampaignLeaderCheck"))
}()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -1650,9 +1650,9 @@ func TestMinResolvedTS(t *testing.T) {
// See https://github.com/tikv/pd/issues/4941
func TestTransferLeaderBack(t *testing.T) {
re := require.New(t)
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/member/changeFrequencyTimes", "return(10)"))
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/changeFrequencyTimes"))
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/member/skipCampaignLeaderCheck"))
}()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
4 changes: 2 additions & 2 deletions tests/server/id/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ func TestCommand(t *testing.T) {

func TestMonotonicID(t *testing.T) {
re := require.New(t)
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/member/changeFrequencyTimes", "return(10)"))
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/changeFrequencyTimes"))
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/member/skipCampaignLeaderCheck"))
}()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
4 changes: 2 additions & 2 deletions tests/server/region_syncer/region_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ func TestPrepareChecker(t *testing.T) {
// ref: https://github.com/tikv/pd/issues/6988
func TestPrepareCheckerWithTransferLeader(t *testing.T) {
re := require.New(t)
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/member/changeFrequencyTimes", "return(10)"))
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/changeFrequencyTimes"))
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/member/skipCampaignLeaderCheck"))
}()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down

0 comments on commit 8e45f9e

Please sign in to comment.