From 3ca82e441f75d6aada8a3d2af1f61a09ae86d5fd Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Wed, 25 Sep 2024 12:28:49 +0800 Subject: [PATCH] tests: make schedulerTestSuite stable Signed-off-by: lhy1024 --- .../pd-ctl/tests/scheduler/scheduler_test.go | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tools/pd-ctl/tests/scheduler/scheduler_test.go b/tools/pd-ctl/tests/scheduler/scheduler_test.go index 80ac1c7ceca..9de1195bed3 100644 --- a/tools/pd-ctl/tests/scheduler/scheduler_test.go +++ b/tools/pd-ctl/tests/scheduler/scheduler_test.go @@ -98,6 +98,14 @@ func (suite *schedulerTestSuite) TearDownTest() { suite.env.Cleanup() } +func (suite *schedulerTestSuite) checkDefaultSchedulers(re *require.Assertions, cmd *cobra.Command, pdAddr string) { + expected := make(map[string]bool) + for _, scheduler := range suite.defaultSchedulers { + expected[scheduler] = true + } + checkSchedulerCommand(re, cmd, pdAddr, nil, expected) +} + func (suite *schedulerTestSuite) TestScheduler() { suite.env.RunTestBasedOnMode(suite.checkScheduler) } @@ -152,18 +160,11 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) { // note: because pdqsort is a unstable sort algorithm, set ApproximateSize for this region. pdTests.MustPutRegion(re, cluster, 1, 1, []byte("a"), []byte("b"), core.SetApproximateSize(10)) - // scheduler show command - expected := map[string]bool{ - "balance-region-scheduler": true, - "balance-leader-scheduler": true, - "balance-hot-region-scheduler": true, - "evict-slow-store-scheduler": true, - } - checkSchedulerCommand(re, cmd, pdAddr, nil, expected) + suite.checkDefaultSchedulers(re, cmd, pdAddr) // scheduler delete command args := []string{"-u", pdAddr, "scheduler", "remove", "balance-region-scheduler"} - expected = map[string]bool{ + expected := map[string]bool{ "balance-leader-scheduler": true, "balance-hot-region-scheduler": true, "evict-slow-store-scheduler": true, @@ -435,6 +436,8 @@ func (suite *schedulerTestSuite) checkSchedulerConfig(cluster *pdTests.TestClust // note: because pdqsort is an unstable sort algorithm, set ApproximateSize for this region. pdTests.MustPutRegion(re, cluster, 1, 1, []byte("a"), []byte("b"), core.SetApproximateSize(10)) + suite.checkDefaultSchedulers(re, cmd, pdAddr) + // test evict-slow-store && evict-slow-trend schedulers config evictSlownessSchedulers := []string{"evict-slow-store-scheduler", "evict-slow-trend-scheduler"} for _, schedulerName := range evictSlownessSchedulers { @@ -620,6 +623,9 @@ func (suite *schedulerTestSuite) checkHotRegionSchedulerConfig(cluster *pdTests. } // note: because pdqsort is an unstable sort algorithm, set ApproximateSize for this region. pdTests.MustPutRegion(re, cluster, 1, 1, []byte("a"), []byte("b"), core.SetApproximateSize(10)) + + suite.checkDefaultSchedulers(re, cmd, pdAddr) + leaderServer := cluster.GetLeaderServer() // test hot region config expected1 := map[string]any{ @@ -799,6 +805,8 @@ func (suite *schedulerTestSuite) checkSchedulerDiagnostic(cluster *pdTests.TestC // note: because pdqsort is an unstable sort algorithm, set ApproximateSize for this region. pdTests.MustPutRegion(re, cluster, 1, 1, []byte("a"), []byte("b"), core.SetApproximateSize(10)) + suite.checkDefaultSchedulers(re, cmd, pdAddr) + echo := mustExec(re, cmd, []string{"-u", pdAddr, "config", "set", "enable-diagnostic", "true"}, nil) re.Contains(echo, "Success!") checkSchedulerDescribeCommand("balance-region-scheduler", "pending", "1 store(s) RegionNotMatchRule; ")