Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Nov 7, 2023
1 parent 1684a14 commit 85b941c
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 34 deletions.
3 changes: 0 additions & 3 deletions pkg/utils/apiutil/serverapi/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ func (h *redirector) matchMicroServiceRedirectRules(r *http.Request) (bool, stri
r.URL.Path = strings.TrimRight(r.URL.Path, "/")
for _, rule := range h.microserviceRedirectRules {
if strings.HasPrefix(r.URL.Path, rule.matchPath) && slice.Contains(rule.matchMethods, r.Method) {
if !h.s.IsServiceEnabled(rule.targetServiceName) {
continue
}
addr, ok := h.s.GetServicePrimaryAddr(r.Context(), rule.targetServiceName)
if !ok || addr == "" {
log.Warn("failed to get the service primary addr when trying to match redirect rules",
Expand Down
29 changes: 14 additions & 15 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,30 +345,29 @@ func (c *RaftCluster) runServiceCheckJob() {
defer logutil.LogPanic()
defer c.wg.Done()

var once sync.Once

checkFn := func() {
if c.isAPIServiceMode {
once.Do(c.initSchedulers)
c.enabledServices.Store(mcsutils.SchedulingServiceName, true)
} else if !c.schedulingController.running.Load() {
c.startSchedulingJobs()
c.enabledServices.Delete(mcsutils.SchedulingServiceName)
}
}
checkFn()

ticker := time.NewTicker(serviceCheckInterval)
failpoint.Inject("highFrequencyServiceCheckJob", func() {
ticker.Stop()
ticker = time.NewTicker(time.Millisecond)
})
defer ticker.Stop()

var cancel context.CancelFunc
for {
select {
case <-c.ctx.Done():
log.Info("service check job is stopped")
if cancel != nil {
cancel()
}
return
case <-ticker.C:
if c.isAPIServiceMode {
c.initSchedulers()
c.enabledServices.Store(mcsutils.SchedulingServiceName, true)
} else if !c.schedulingController.running.Load() {
c.startSchedulingJobs()
c.enabledServices.Delete(mcsutils.SchedulingServiceName)
}
checkFn()
}
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/integrations/mcs/scheduling/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func persistConfig(re *require.Assertions, pdLeaderServer *tests.TestServer) {

func (suite *configTestSuite) TestSchedulerConfigWatch() {
re := suite.Require()

// Make sure the config is persisted before the watcher is created.
persistConfig(re, suite.pdLeaderServer)
// Create a config watcher.
Expand Down
3 changes: 0 additions & 3 deletions tests/pdctl/hot/hot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"time"

"github.com/docker/go-units"
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -50,7 +49,6 @@ func TestHotTestSuite(t *testing.T) {
}

func (suite *hotTestSuite) TestHot() {
suite.NoError(failpoint.Enable("github.com/tikv/pd/server/cluster/highFrequencyServiceCheckJob", `return(true)`))
var start time.Time
start = start.Add(time.Hour)
opts := []tests.ConfigOption{
Expand All @@ -68,7 +66,6 @@ func (suite *hotTestSuite) TestHot() {
env.RunTestInTwoModes(suite.checkHotWithoutHotPeer)
env = tests.NewSchedulingTestEnvironment(suite.T(), opts...)
env.RunTestInTwoModes(suite.checkHotWithStoreID)
suite.NoError(failpoint.Disable("github.com/tikv/pd/server/cluster/highFrequencyServiceCheckJob"))
}

func (suite *hotTestSuite) checkHot(cluster *tests.TestCluster) {
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 @@ -22,7 +22,6 @@ import (
"testing"
"time"

"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -573,7 +572,6 @@ func TestForwardSchedulerRequest(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
re.NoError(failpoint.Enable("github.com/tikv/pd/server/cluster/highFrequencyServiceCheckJob", `return(true)`))
cluster, err := tests.NewTestAPICluster(ctx, 1)
re.NoError(err)
re.NoError(cluster.RunInitialServers())
Expand Down Expand Up @@ -609,5 +607,4 @@ func TestForwardSchedulerRequest(t *testing.T) {
checkSchedulerWithStatusCommand("paused", []string{
"balance-leader-scheduler",
})
re.NoError(failpoint.Disable("github.com/tikv/pd/server/cluster/highFrequencyServiceCheckJob"))
}
3 changes: 0 additions & 3 deletions tests/server/api/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"testing"
"time"

"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/stretchr/testify/suite"
"github.com/tikv/pd/pkg/core"
Expand Down Expand Up @@ -53,7 +52,6 @@ func TestOperatorTestSuite(t *testing.T) {
}

func (suite *operatorTestSuite) TestOperator() {
suite.NoError(failpoint.Enable("github.com/tikv/pd/server/cluster/highFrequencyServiceCheckJob", `return(true)`))
opts := []tests.ConfigOption{
func(conf *config.Config, serverName string) {
conf.Replication.MaxReplicas = 1
Expand All @@ -72,7 +70,6 @@ func (suite *operatorTestSuite) TestOperator() {
}
env = tests.NewSchedulingTestEnvironment(suite.T(), opts...)
env.RunTestInTwoModes(suite.checkTransferRegionWithPlacementRule)
suite.NoError(failpoint.Disable("github.com/tikv/pd/server/cluster/highFrequencyServiceCheckJob"))
}

func (suite *operatorTestSuite) checkAddRemovePeer(cluster *tests.TestCluster) {
Expand Down
2 changes: 0 additions & 2 deletions tests/server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,6 @@ func TestTransferLeaderForScheduler(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
re.NoError(failpoint.Enable("github.com/tikv/pd/server/cluster/highFrequencyServiceCheckJob", `return(true)`))
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/schedule/changeCoordinatorTicker", `return(true)`))
tc, err := tests.NewTestCluster(ctx, 2)
defer tc.Destroy()
Expand Down Expand Up @@ -1364,7 +1363,6 @@ func TestTransferLeaderForScheduler(t *testing.T) {
checkEvictLeaderSchedulerExist(re, schedulersController, true)
checkEvictLeaderStoreIDs(re, schedulersController, []uint64{1, 2})

re.NoError(failpoint.Disable("github.com/tikv/pd/server/cluster/highFrequencyServiceCheckJob"))
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/schedule/changeCoordinatorTicker"))
}

Expand Down
4 changes: 0 additions & 4 deletions tests/server/region_syncer/region_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ func TestPrepareChecker(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
re.NoError(failpoint.Enable("github.com/tikv/pd/server/cluster/highFrequencyServiceCheckJob", `return(true)`))
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/schedule/changeCoordinatorTicker", `return(true)`))
cluster, err := tests.NewTestCluster(ctx, 1, func(conf *config.Config, serverName string) { conf.PDServerCfg.UseRegionStorage = true })
defer cluster.Destroy()
Expand Down Expand Up @@ -244,7 +243,6 @@ func TestPrepareChecker(t *testing.T) {
}
time.Sleep(time.Second)
re.True(rc.IsPrepared())
re.NoError(failpoint.Disable("github.com/tikv/pd/server/cluster/highFrequencyServiceCheckJob"))
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/schedule/changeCoordinatorTicker"))
}

Expand All @@ -253,7 +251,6 @@ func TestPrepareCheckerWithTransferLeader(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
re.NoError(failpoint.Enable("github.com/tikv/pd/server/cluster/highFrequencyServiceCheckJob", `return(true)`))
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/schedule/changeCoordinatorTicker", `return(true)`))
cluster, err := tests.NewTestCluster(ctx, 1, func(conf *config.Config, serverName string) { conf.PDServerCfg.UseRegionStorage = true })
defer cluster.Destroy()
Expand Down Expand Up @@ -292,7 +289,6 @@ func TestPrepareCheckerWithTransferLeader(t *testing.T) {
re.NoError(err)
re.Equal("pd1", cluster.WaitLeader())
re.True(rc.IsPrepared())
re.NoError(failpoint.Disable("github.com/tikv/pd/server/cluster/highFrequencyServiceCheckJob"))
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/schedule/changeCoordinatorTicker"))
}

Expand Down

0 comments on commit 85b941c

Please sign in to comment.