From 8193d290bfd12bafc0458099eeef90d2e36c5ada Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Wed, 25 Sep 2024 12:09:47 +0800 Subject: [PATCH] checkDefaultSchedulers Signed-off-by: lhy1024 --- .../pd-ctl/tests/scheduler/scheduler_test.go | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/tools/pd-ctl/tests/scheduler/scheduler_test.go b/tools/pd-ctl/tests/scheduler/scheduler_test.go index b5a2128752b..c20342686a9 100644 --- a/tools/pd-ctl/tests/scheduler/scheduler_test.go +++ b/tools/pd-ctl/tests/scheduler/scheduler_test.go @@ -98,6 +98,15 @@ func (suite *schedulerTestSuite) TearDownTest() { suite.env.Cleanup() } +func (suite *schedulerTestSuite) checkDefaultSchedulers(re *require.Assertions, cmd *cobra.Command, pdAddr string) { + // scheduler show command + 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.RunTestInTwoModes(suite.checkScheduler) } @@ -172,18 +181,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(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, @@ -705,7 +707,7 @@ 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; ") @@ -740,3 +742,23 @@ func mightExec(re *require.Assertions, cmd *cobra.Command, args []string, v any) } json.Unmarshal(output, v) } + +func checkSchedulerCommand(re *require.Assertions, cmd *cobra.Command, pdAddr string, args []string, expected map[string]bool) { + if args != nil { + echo := mustExec(re, cmd, args, nil) + re.Contains(echo, "Success!") + } + testutil.Eventually(re, func() bool { + var schedulers []string + mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "show"}, &schedulers) + if len(schedulers) != len(expected) { + return false + } + for _, scheduler := range schedulers { + if _, ok := expected[scheduler]; !ok { + return false + } + } + return true + }) +}