Skip to content

Commit

Permalink
make test stable
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <admin@liudos.us>
  • Loading branch information
lhy1024 committed Nov 23, 2023
1 parent 8a6f56d commit b777d28
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions scripts/ci-subtask.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ else
weight() {
[[ $1 == "github.com/tikv/pd/server/api" ]] && return 30
[[ $1 == "github.com/tikv/pd/pkg/schedule" ]] && return 30
[[ $1 == "pd/tests/server/api" ]] && return 30
[[ $1 =~ "pd/tests" ]] && return 5
return 1
}
Expand Down
38 changes: 24 additions & 14 deletions tests/server/api/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,37 @@ func (suite *regionTestSuite) checkSplitRegions(cluster *tests.TestCluster) {
}

func (suite *regionTestSuite) TestAccelerateRegionsScheduleInRange() {
env := tests.NewSchedulingTestEnvironment(suite.T())
env := tests.NewSchedulingTestEnvironment(suite.T(), func(conf *config.Config, serverName string) {
// FIXME: enable placement rules
conf.Replication.EnablePlacementRules = false
conf.Replication.MaxReplicas = 1
})
env.RunTestInTwoModes(suite.checkAccelerateRegionsScheduleInRange)
}

func (suite *regionTestSuite) checkAccelerateRegionsScheduleInRange(cluster *tests.TestCluster) {
leader := cluster.GetLeaderServer()
urlPrefix := leader.GetAddr() + "/pd/api/v1"
re := suite.Require()
for i := 13; i <= 15; i++ {
for i := 1; i <= 3; i++ {
s1 := &metapb.Store{
Id: uint64(i),
State: metapb.StoreState_Up,
NodeState: metapb.NodeState_Serving,
}
tests.MustPutStore(re, cluster, s1)
}
r1 := core.NewTestRegionInfo(557, 13, []byte("a1"), []byte("a2"))
r2 := core.NewTestRegionInfo(558, 14, []byte("a2"), []byte("a3"))
r3 := core.NewTestRegionInfo(559, 15, []byte("a3"), []byte("a4"))
r1 := core.NewTestRegionInfo(557, 1, []byte("a1"), []byte("a2"))
r2 := core.NewTestRegionInfo(558, 2, []byte("a2"), []byte("a3"))
r3 := core.NewTestRegionInfo(559, 3, []byte("a3"), []byte("a4"))
tests.MustPutRegionInfo(re, cluster, r1)
tests.MustPutRegionInfo(re, cluster, r2)
tests.MustPutRegionInfo(re, cluster, r3)
suite.checkRegionCount(cluster, 3)

body := fmt.Sprintf(`{"start_key":"%s", "end_key": "%s"}`, hex.EncodeToString([]byte("a1")), hex.EncodeToString([]byte("a3")))
err := tu.CheckPostJSON(testDialClient, fmt.Sprintf("%s/regions/accelerate-schedule", urlPrefix), []byte(body), tu.StatusOK(re))
err := tu.CheckPostJSON(testDialClient, fmt.Sprintf("%s/regions/accelerate-schedule", urlPrefix), []byte(body),
tu.StatusOK(re))
suite.NoError(err)
idList := leader.GetRaftCluster().GetSuspectRegions()
if sche := cluster.GetSchedulingPrimaryServer(); sche != nil {
Expand All @@ -116,27 +121,31 @@ func (suite *regionTestSuite) checkAccelerateRegionsScheduleInRange(cluster *tes
}

func (suite *regionTestSuite) TestAccelerateRegionsScheduleInRanges() {
env := tests.NewSchedulingTestEnvironment(suite.T())
env := tests.NewSchedulingTestEnvironment(suite.T(), func(conf *config.Config, serverName string) {
// FIXME: enable placement rules
conf.Replication.EnablePlacementRules = false
conf.Replication.MaxReplicas = 1
})
env.RunTestInTwoModes(suite.checkAccelerateRegionsScheduleInRanges)
}

func (suite *regionTestSuite) checkAccelerateRegionsScheduleInRanges(cluster *tests.TestCluster) {
leader := cluster.GetLeaderServer()
urlPrefix := leader.GetAddr() + "/pd/api/v1"
re := suite.Require()
for i := 13; i <= 17; i++ {
for i := 1; i <= 5; i++ {
s1 := &metapb.Store{
Id: uint64(i),
State: metapb.StoreState_Up,
NodeState: metapb.NodeState_Serving,
}
tests.MustPutStore(re, cluster, s1)
}
r1 := core.NewTestRegionInfo(557, 13, []byte("a1"), []byte("a2"))
r2 := core.NewTestRegionInfo(558, 14, []byte("a2"), []byte("a3"))
r3 := core.NewTestRegionInfo(559, 15, []byte("a3"), []byte("a4"))
r4 := core.NewTestRegionInfo(560, 16, []byte("a4"), []byte("a5"))
r5 := core.NewTestRegionInfo(561, 17, []byte("a5"), []byte("a6"))
r1 := core.NewTestRegionInfo(557, 1, []byte("a1"), []byte("a2"))
r2 := core.NewTestRegionInfo(558, 2, []byte("a2"), []byte("a3"))
r3 := core.NewTestRegionInfo(559, 3, []byte("a3"), []byte("a4"))
r4 := core.NewTestRegionInfo(560, 4, []byte("a4"), []byte("a5"))
r5 := core.NewTestRegionInfo(561, 5, []byte("a5"), []byte("a6"))
tests.MustPutRegionInfo(re, cluster, r1)
tests.MustPutRegionInfo(re, cluster, r2)
tests.MustPutRegionInfo(re, cluster, r3)
Expand All @@ -146,7 +155,8 @@ func (suite *regionTestSuite) checkAccelerateRegionsScheduleInRanges(cluster *te

body := fmt.Sprintf(`[{"start_key":"%s", "end_key": "%s"}, {"start_key":"%s", "end_key": "%s"}]`,
hex.EncodeToString([]byte("a1")), hex.EncodeToString([]byte("a3")), hex.EncodeToString([]byte("a4")), hex.EncodeToString([]byte("a6")))
err := tu.CheckPostJSON(testDialClient, fmt.Sprintf("%s/regions/accelerate-schedule/batch", urlPrefix), []byte(body), tu.StatusOK(re))
err := tu.CheckPostJSON(testDialClient, fmt.Sprintf("%s/regions/accelerate-schedule/batch", urlPrefix), []byte(body),
tu.StatusOK(re))
suite.NoError(err)
idList := leader.GetRaftCluster().GetSuspectRegions()
if sche := cluster.GetSchedulingPrimaryServer(); sche != nil {
Expand Down

0 comments on commit b777d28

Please sign in to comment.