Skip to content

Commit

Permalink
Merge branch 'sche-redirect9' of github.com:lhy1024/pd into sche-redi…
Browse files Browse the repository at this point in the history
…rect9-1
  • Loading branch information
lhy1024 committed Nov 2, 2023
2 parents 4005db1 + e3bf609 commit eb02dd5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 45 deletions.
6 changes: 3 additions & 3 deletions tests/integrations/mcs/scheduling/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func TestConfigForward(t *testing.T) {
sche.GetPersistConfig().GetScheduleConfig().LeaderScheduleLimit = 100
re.Equal(100, int(sche.GetScheduleConfig().LeaderScheduleLimit))
testutil.ReadGetJSON(re, testDialClient, urlPrefix, &cfg)
re.Equal(cfg["schedule"].(map[string]interface{})["leader-schedule-limit"], float64(sche.GetScheduleConfig().LeaderScheduleLimit))
re.Equal(100., cfg["schedule"].(map[string]interface{})["leader-schedule-limit"])

// Test schedule
urlPrefix = fmt.Sprintf("%s/pd/api/v1/config/schedule", addr)
Expand All @@ -316,7 +316,7 @@ func TestConfigForward(t *testing.T) {
sche.GetPersistConfig().GetScheduleConfig().LeaderScheduleLimit = 4
re.Equal(4, int(sche.GetScheduleConfig().LeaderScheduleLimit))
testutil.ReadGetJSON(re, testDialClient, urlPrefix, &cfg)
re.Equal(cfg["leader-schedule-limit"], float64(sche.GetScheduleConfig().LeaderScheduleLimit))
re.Equal(4., cfg["leader-schedule-limit"])

// Test replicate
urlPrefix = fmt.Sprintf("%s/pd/api/v1/config/replicate", addr)
Expand All @@ -326,7 +326,7 @@ func TestConfigForward(t *testing.T) {
sche.GetPersistConfig().GetReplicationConfig().MaxReplicas = 5
re.Equal(5, int(sche.GetReplicationConfig().MaxReplicas))
testutil.ReadGetJSON(re, testDialClient, urlPrefix, &cfg)
re.Equal(cfg["max-replicas"], float64(sche.GetReplicationConfig().MaxReplicas))
re.Equal(5., cfg["max-replicas"])
}
env := tests.NewSchedulingTestEnvironment(t)
env.RunTestInAPIMode(checkConfigForward)
Expand Down
88 changes: 46 additions & 42 deletions tests/pdctl/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/stretchr/testify/suite"
sc "github.com/tikv/pd/pkg/schedule/config"
"github.com/tikv/pd/pkg/schedule/placement"
"github.com/tikv/pd/pkg/utils/testutil"
"github.com/tikv/pd/pkg/utils/typeutil"
"github.com/tikv/pd/server/config"
"github.com/tikv/pd/tests"
Expand Down Expand Up @@ -289,25 +290,22 @@ func (suite *configTestSuite) checkConfig(cluster *tests.TestCluster) {
re.Contains(string(output), "is invalid")
}

func TestPlacementRules(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cluster, err := tests.NewTestCluster(ctx, 1)
re.NoError(err)
err = cluster.RunInitialServers()
re.NoError(err)
cluster.WaitLeader()
pdAddr := cluster.GetConfig().GetClientURL()
func (suite *configTestSuite) TestPlacementRules() {
env := tests.NewSchedulingTestEnvironment(suite.T())
env.RunTestInTwoModes(suite.checkPlacementRules)
}

func (suite *configTestSuite) checkPlacementRules(cluster *tests.TestCluster) {
re := suite.Require()
leaderServer := cluster.GetLeaderServer()
pdAddr := leaderServer.GetAddr()
cmd := pdctlCmd.GetRootCmd()

store := &metapb.Store{
Id: 1,
State: metapb.StoreState_Up,
LastHeartbeat: time.Now().UnixNano(),
}
leaderServer := cluster.GetLeaderServer()
re.NoError(leaderServer.BootstrapCluster())
tests.MustPutStore(re, cluster, store)
defer cluster.Destroy()

Expand Down Expand Up @@ -386,25 +384,22 @@ func TestPlacementRules(t *testing.T) {
re.Equal([2]string{"pd", "test1"}, rules[0].Key())
}

func TestPlacementRuleGroups(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cluster, err := tests.NewTestCluster(ctx, 1)
re.NoError(err)
err = cluster.RunInitialServers()
re.NoError(err)
cluster.WaitLeader()
pdAddr := cluster.GetConfig().GetClientURL()
func (suite *configTestSuite) TestPlacementRuleGroups() {
env := tests.NewSchedulingTestEnvironment(suite.T())
env.RunTestInTwoModes(suite.checkPlacementRuleGroups)
}

func (suite *configTestSuite) checkPlacementRuleGroups(cluster *tests.TestCluster) {
re := suite.Require()
leaderServer := cluster.GetLeaderServer()
pdAddr := leaderServer.GetAddr()
cmd := pdctlCmd.GetRootCmd()

store := &metapb.Store{
Id: 1,
State: metapb.StoreState_Up,
LastHeartbeat: time.Now().UnixNano(),
}
leaderServer := cluster.GetLeaderServer()
re.NoError(leaderServer.BootstrapCluster())
tests.MustPutStore(re, cluster, store)
defer cluster.Destroy()

Expand Down Expand Up @@ -460,25 +455,22 @@ func TestPlacementRuleGroups(t *testing.T) {
re.Contains(string(output), "404")
}

func TestPlacementRuleBundle(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cluster, err := tests.NewTestCluster(ctx, 1)
re.NoError(err)
err = cluster.RunInitialServers()
re.NoError(err)
cluster.WaitLeader()
pdAddr := cluster.GetConfig().GetClientURL()
func (suite *configTestSuite) TestPlacementRuleBundle() {
env := tests.NewSchedulingTestEnvironment(suite.T())
env.RunTestInTwoModes(suite.checkPlacementRuleBundle)
}

func (suite *configTestSuite) checkPlacementRuleBundle(cluster *tests.TestCluster) {
re := suite.Require()
leaderServer := cluster.GetLeaderServer()
pdAddr := leaderServer.GetAddr()
cmd := pdctlCmd.GetRootCmd()

store := &metapb.Store{
Id: 1,
State: metapb.StoreState_Up,
LastHeartbeat: time.Now().UnixNano(),
}
leaderServer := cluster.GetLeaderServer()
re.NoError(leaderServer.BootstrapCluster())
tests.MustPutStore(re, cluster, store)
defer cluster.Destroy()

Expand Down Expand Up @@ -678,7 +670,9 @@ func (suite *configTestSuite) checkUpdateDefaultReplicaConfig(cluster *tests.Tes
re.NoError(err)
replicationCfg := sc.ReplicationConfig{}
re.NoError(json.Unmarshal(output, &replicationCfg))
re.Equal(expect, replicationCfg.MaxReplicas)
testutil.Eventually(re, func() bool { // wait for the config to be synced to the scheduling server
return replicationCfg.MaxReplicas == expect
})
}

checkLocationLabels := func(expect int) {
Expand All @@ -687,7 +681,9 @@ func (suite *configTestSuite) checkUpdateDefaultReplicaConfig(cluster *tests.Tes
re.NoError(err)
replicationCfg := sc.ReplicationConfig{}
re.NoError(json.Unmarshal(output, &replicationCfg))
re.Len(replicationCfg.LocationLabels, expect)
testutil.Eventually(re, func() bool { // wait for the config to be synced to the scheduling server
return len(replicationCfg.LocationLabels) == expect
})
}

checkIsolationLevel := func(expect string) {
Expand All @@ -696,7 +692,9 @@ func (suite *configTestSuite) checkUpdateDefaultReplicaConfig(cluster *tests.Tes
re.NoError(err)
replicationCfg := sc.ReplicationConfig{}
re.NoError(json.Unmarshal(output, &replicationCfg))
re.Equal(replicationCfg.IsolationLevel, expect)
testutil.Eventually(re, func() bool { // wait for the config to be synced to the scheduling server
return replicationCfg.IsolationLevel == expect
})
}

checkRuleCount := func(expect int) {
Expand All @@ -705,7 +703,9 @@ func (suite *configTestSuite) checkUpdateDefaultReplicaConfig(cluster *tests.Tes
re.NoError(err)
rule := placement.Rule{}
re.NoError(json.Unmarshal(output, &rule))
re.Equal(expect, rule.Count)
testutil.Eventually(re, func() bool { // wait for the config to be synced to the scheduling server
return rule.Count == expect
})
}

checkRuleLocationLabels := func(expect int) {
Expand All @@ -714,7 +714,9 @@ func (suite *configTestSuite) checkUpdateDefaultReplicaConfig(cluster *tests.Tes
re.NoError(err)
rule := placement.Rule{}
re.NoError(json.Unmarshal(output, &rule))
re.Len(rule.LocationLabels, expect)
testutil.Eventually(re, func() bool { // wait for the config to be synced to the scheduling server
return len(rule.LocationLabels) == expect
})
}

checkRuleIsolationLevel := func(expect string) {
Expand All @@ -723,7 +725,9 @@ func (suite *configTestSuite) checkUpdateDefaultReplicaConfig(cluster *tests.Tes
re.NoError(err)
rule := placement.Rule{}
re.NoError(json.Unmarshal(output, &rule))
re.Equal(rule.IsolationLevel, expect)
testutil.Eventually(re, func() bool { // wait for the config to be synced to the scheduling server
return rule.IsolationLevel == expect
})
}

// update successfully when placement rules is not enabled.
Expand Down
3 changes: 3 additions & 0 deletions tests/server/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ func (suite *configTestSuite) checkConfigAll(cluster *tests.TestCluster) {
cfg.Log.Level = "warn"
cfg.ReplicationMode.DRAutoSync.LabelKey = "foobar"
cfg.ReplicationMode.ReplicationMode = "dr-auto-sync"
if cfg.PDServerCfg.DashboardAddress == "auto" {
cfg.PDServerCfg.DashboardAddress = newCfg1.PDServerCfg.DashboardAddress
}
v, err := versioninfo.ParseVersion("v4.0.0-beta")
suite.NoError(err)
cfg.ClusterVersion = *v
Expand Down

0 comments on commit eb02dd5

Please sign in to comment.