Skip to content

Commit

Permalink
Replace failpoint with testing.Testing() to polish codes.
Browse files Browse the repository at this point in the history
Signed-off-by: lucasliang <[email protected]>
  • Loading branch information
LykxSassinator committed Aug 23, 2023
1 parent 566c248 commit b29d736
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pkg/schedule/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"strconv"
"sync"
"testing"
"time"

"github.com/pingcap/errors"
Expand Down Expand Up @@ -639,9 +640,9 @@ func (c *Coordinator) ResetHotSpotMetrics() {
// ShouldRun returns true if the coordinator should run.
func (c *Coordinator) ShouldRun() bool {
isSynced := c.cluster.GetStoreConfig().IsSynced()
failpoint.Inject("mockStoreConfigSynced", func() {
if testing.Testing() {
isSynced = true
})
}
return c.prepareChecker.check(c.cluster.GetBasicCluster()) && isSynced
}

Expand Down
8 changes: 7 additions & 1 deletion tests/integrations/mcs/scheduling/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ func (suite *configTestSuite) TestSchedulerConfigWatch() {
)
testutil.Eventually(re, func() bool {
schedulerNames = schedulerController.GetSchedulerNames()
return len(schedulerNames) == len(sc.DefaultSchedulers)
targetCount := len(sc.DefaultSchedulers)
// In the previous case, StoreConfig of raft-kv2 has been persisted. So, it might
// have EvictSlowTrendName.
if exists, _ := schedulerController.IsSchedulerExisted(schedulers.EvictSlowTrendName); exists {
targetCount += 1
}
return len(schedulerNames) == targetCount
})
// Check all default schedulers' configs.
for _, schedulerName := range schedulerNames {
Expand Down
3 changes: 0 additions & 3 deletions tests/pdctl/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"
"time"

"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/stretchr/testify/require"
sc "github.com/tikv/pd/pkg/schedule/config"
Expand All @@ -33,7 +32,6 @@ import (

func TestScheduler(t *testing.T) {
re := require.New(t)
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/schedule/mockStoreConfigSynced", "return(true)"))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cluster, err := tests.NewTestCluster(ctx, 1)
Expand Down Expand Up @@ -487,5 +485,4 @@ func TestScheduler(t *testing.T) {
err = leaderServer.GetServer().SetScheduleConfig(*cfg)
re.NoError(err)
checkSchedulerWithStatusCommand(nil, "disabled", nil)
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/schedule/mockStoreConfigSynced"))
}

0 comments on commit b29d736

Please sign in to comment.