Skip to content

Commit

Permalink
use const name
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Sep 26, 2023
1 parent a57ed68 commit a54203d
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions tests/integrations/mcs/resourcemanager/resource_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ func (suite *resourceManagerClientTestSuite) resignAndWaitLeader() {
func (suite *resourceManagerClientTestSuite) TestWatchResourceGroup() {
re := suite.Require()
cli := suite.client
const groupNamePrefix = "watch_test"
group := &rmpb.ResourceGroup{
Name: "watch_test",
Name: groupNamePrefix,
Mode: rmpb.GroupMode_RUMode,
RUSettings: &rmpb.GroupRequestUnitSettings{
RU: &rmpb.TokenBucket{
Expand All @@ -198,7 +199,7 @@ func (suite *resourceManagerClientTestSuite) TestWatchResourceGroup() {
var meta *rmpb.ResourceGroup
groupsNum := 10
for i := 0; i < groupsNum; i++ {
group.Name = "watch_test" + strconv.Itoa(i)
group.Name = groupNamePrefix + strconv.Itoa(i)
resp, err := cli.AddResourceGroup(suite.ctx, group)
re.NoError(err)
re.Contains(resp, "Success!")
Expand All @@ -221,15 +222,15 @@ func (suite *resourceManagerClientTestSuite) TestWatchResourceGroup() {
}
}
for i := 0; i < groupsNum; i++ {
group.Name = "watch_test" + strconv.Itoa(i)
group.Name = groupNamePrefix + strconv.Itoa(i)
modifySettings(group, 20000)
resp, err := cli.ModifyResourceGroup(suite.ctx, group)
re.NoError(err)
re.Contains(resp, "Success!")
}
for i := 0; i < groupsNum; i++ {
testutil.Eventually(re, func() bool {
name := "watch_test" + strconv.Itoa(i)
name := groupNamePrefix + strconv.Itoa(i)
meta = controller.GetActiveResourceGroup(name)
if meta != nil {
return meta.RUSettings.RU.Settings.FillRate == uint64(20000)
Expand All @@ -240,7 +241,7 @@ func (suite *resourceManagerClientTestSuite) TestWatchResourceGroup() {

// Mock reset watch stream
re.NoError(failpoint.Enable("github.com/tikv/pd/client/resource_group/controller/watchStreamError", "return(true)"))
group.Name = "watch_test" + strconv.Itoa(groupsNum)
group.Name = groupNamePrefix + strconv.Itoa(groupsNum)
resp, err := cli.AddResourceGroup(suite.ctx, group)
re.NoError(err)
re.Contains(resp, "Success!")
Expand All @@ -262,7 +263,7 @@ func (suite *resourceManagerClientTestSuite) TestWatchResourceGroup() {
suite.cleanupResourceGroups()
for i := 0; i < groupsNum; i++ {
testutil.Eventually(re, func() bool {
name := "watch_test" + strconv.Itoa(i)
name := groupNamePrefix + strconv.Itoa(i)
meta = controller.GetActiveResourceGroup(name)
return meta == nil
}, testutil.WithTickInterval(50*time.Millisecond))
Expand Down Expand Up @@ -599,9 +600,10 @@ func (suite *resourceManagerClientTestSuite) TestResourcePenalty() {
re := suite.Require()
cli := suite.client

groupNames := []string{"penalty_test1", "penalty_test2"}
// Mock add 2 resource groups.
group := &rmpb.ResourceGroup{
Name: "penalty_test",
Name: groupNames[0],
Mode: rmpb.GroupMode_RUMode,
RUSettings: &rmpb.GroupRequestUnitSettings{
RU: &rmpb.TokenBucket{
Expand All @@ -612,8 +614,8 @@ func (suite *resourceManagerClientTestSuite) TestResourcePenalty() {
},
},
}
for i := 0; i < 2; i++ {
group.Name = "penalty_test" + strconv.Itoa(i)
for _, name := range groupNames {
group.Name = name
resp, err := cli.AddResourceGroup(suite.ctx, group)
re.NoError(err)
re.Contains(resp, "Success!")
Expand All @@ -629,7 +631,7 @@ func (suite *resourceManagerClientTestSuite) TestResourcePenalty() {
c, _ := controller.NewResourceGroupController(suite.ctx, 1, cli, cfg, controller.EnableSingleGroupByKeyspace())
c.Start(suite.ctx)

resourceGroupName := "penalty_test0"
resourceGroupName := groupNames[0]
// init
req := controller.NewTestRequestInfo(false, 0, 2 /* store2 */)
resp := controller.NewTestResponseInfo(0, time.Duration(30), true)
Expand Down Expand Up @@ -688,7 +690,7 @@ func (suite *resourceManagerClientTestSuite) TestResourcePenalty() {
re.NoError(err)

// from different group, should be zero
resourceGroupName = "penalty_test1"
resourceGroupName = groupNames[1]
req4 := controller.NewTestRequestInfo(true, 50, 1 /* store2 */)
resp4 := controller.NewTestResponseInfo(0, time.Duration(10), true)
_, penalty, err = c.OnRequestWait(suite.ctx, resourceGroupName, req4)
Expand Down Expand Up @@ -1092,8 +1094,9 @@ func (suite *resourceManagerClientTestSuite) TestResourceManagerClientDegradedMo
re := suite.Require()
cli := suite.client

groupName := "mode_test"
group := &rmpb.ResourceGroup{
Name: "mode_test",
Name: groupName,
Mode: rmpb.GroupMode_RUMode,
RUSettings: &rmpb.GroupRequestUnitSettings{
RU: &rmpb.TokenBucket{
Expand Down Expand Up @@ -1128,16 +1131,15 @@ func (suite *resourceManagerClientTestSuite) TestResourceManagerClientDegradedMo
rruTokensAtATime: 0,
wruTokensAtATime: 2,
}
resourceName := "mode_test"
controller.OnRequestWait(suite.ctx, resourceName, tc.makeWriteRequest())
controller.OnRequestWait(suite.ctx, groupName, tc.makeWriteRequest())
time.Sleep(time.Second * 2)
beginTime := time.Now()
// This is used to make sure resource group in lowRU.
for i := 0; i < 100; i++ {
controller.OnRequestWait(suite.ctx, resourceName, tc2.makeWriteRequest())
controller.OnRequestWait(suite.ctx, groupName, tc2.makeWriteRequest())
}
for i := 0; i < 100; i++ {
controller.OnRequestWait(suite.ctx, resourceName, tc.makeWriteRequest())
controller.OnRequestWait(suite.ctx, groupName, tc.makeWriteRequest())
}
endTime := time.Now()
// we can not check `inDegradedMode` because of data race.
Expand Down Expand Up @@ -1234,35 +1236,41 @@ func (suite *resourceManagerClientTestSuite) TestCheckBackgroundJobs() {
re := suite.Require()
cli := suite.client

enableBackgroundGroup := func(enable bool) string {
if enable {
return "background_enable"
} else {
return "background_unable"
}
}
// Mock add resource group.
group := &rmpb.ResourceGroup{
Name: "background_enable",
Name: enableBackgroundGroup(false),
Mode: rmpb.GroupMode_RUMode,
RUSettings: &rmpb.GroupRequestUnitSettings{
RU: &rmpb.TokenBucket{Settings: &rmpb.TokenLimitSettings{}},
},
BackgroundSettings: &rmpb.BackgroundSettings{JobTypes: []string{"br", "lightning"}},
}
resp, err := cli.AddResourceGroup(suite.ctx, group)
re.NoError(err)
re.Contains(resp, "Success!")
group.Name = "background_unable"
group.BackgroundSettings = nil
group.Name = enableBackgroundGroup(true)
group.BackgroundSettings = &rmpb.BackgroundSettings{JobTypes: []string{"br", "lightning"}}
resp, err = cli.AddResourceGroup(suite.ctx, group)
re.NoError(err)
re.Contains(resp, "Success!")

c, _ := controller.NewResourceGroupController(suite.ctx, 1, cli, nil)
c.Start(suite.ctx)

resourceGroupName := "background_unable"
resourceGroupName := enableBackgroundGroup(false)
re.False(c.IsBackgroundRequest(suite.ctx, resourceGroupName, "internal_default"))
// test fallback for nil.
re.False(c.IsBackgroundRequest(suite.ctx, resourceGroupName, "internal_lightning"))
re.False(c.IsBackgroundRequest(suite.ctx, resourceGroupName, "internal_ddl"))
re.False(c.IsBackgroundRequest(suite.ctx, resourceGroupName, ""))

resourceGroupName = "background_enable"
resourceGroupName = enableBackgroundGroup(true)
re.True(c.IsBackgroundRequest(suite.ctx, resourceGroupName, "internal_br"))
re.True(c.IsBackgroundRequest(suite.ctx, resourceGroupName, "internal_lightning"))
// test fallback for nil.
Expand All @@ -1288,14 +1296,14 @@ func (suite *resourceManagerClientTestSuite) TestCheckBackgroundJobs() {
return false
}, testutil.WithTickInterval(50*time.Millisecond))

resourceGroupName = "background_unable"
resourceGroupName = enableBackgroundGroup(false)
re.False(c.IsBackgroundRequest(suite.ctx, resourceGroupName, "internal_default"))
// test fallback for `"lightning", "ddl"`.
re.True(c.IsBackgroundRequest(suite.ctx, resourceGroupName, "internal_lightning"))
re.True(c.IsBackgroundRequest(suite.ctx, resourceGroupName, "internal_ddl"))
re.False(c.IsBackgroundRequest(suite.ctx, resourceGroupName, ""))

resourceGroupName = "background_enable"
resourceGroupName = enableBackgroundGroup(true)
re.True(c.IsBackgroundRequest(suite.ctx, resourceGroupName, "internal_br"))
re.True(c.IsBackgroundRequest(suite.ctx, resourceGroupName, "internal_lightning"))
// test fallback for `"lightning", "ddl"`.
Expand Down

0 comments on commit a54203d

Please sign in to comment.