-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ddl: more test cases on
admin pause/resume
(#44783)
close #44762
- Loading branch information
Showing
10 changed files
with
1,214 additions
and
528 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "adminpause", | ||
srcs = [ | ||
"ddl_data_generation.go", | ||
"ddl_stmt_cases.go", | ||
"global.go", | ||
], | ||
importpath = "github.com/pingcap/tidb/ddl/tests/adminpause", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//ddl", | ||
"//domain", | ||
"//parser/model", | ||
"//testkit", | ||
"//util/logutil", | ||
], | ||
) | ||
|
||
go_test( | ||
name = "adminpause_test", | ||
timeout = "moderate", | ||
srcs = [ | ||
"main_test.go", | ||
"pause_cancel_test.go", | ||
"pause_negative_test.go", | ||
"pause_resume_test.go", | ||
], | ||
embed = [":adminpause"], | ||
flaky = True, | ||
race = "on", | ||
shard_count = 14, | ||
deps = [ | ||
"//config", | ||
"//ddl", | ||
"//ddl/testutil", | ||
"//ddl/util/callback", | ||
"//domain", | ||
"//errno", | ||
"//parser/model", | ||
"//testkit", | ||
"//testkit/testsetup", | ||
"//util/sqlexec", | ||
"@com_github_pingcap_failpoint//:failpoint", | ||
"@com_github_stretchr_testify//require", | ||
"@org_uber_go_atomic//:atomic", | ||
"@org_uber_go_goleak//:goleak", | ||
"@org_uber_go_zap//:zap", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
// Copyright 2023 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package adminpause | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"time" | ||
|
||
"github.com/pingcap/tidb/testkit" | ||
) | ||
|
||
// AgeMax limits the max number of tuple generated for t_user.age | ||
const AgeMax int = 120 | ||
|
||
// TestTableUser indicates the columns of table `t_user` to generate tuples | ||
type TestTableUser struct { | ||
id int | ||
tenant string | ||
name string | ||
age int | ||
province string | ||
city string | ||
phone string | ||
createdTime time.Time | ||
updatedTime time.Time | ||
} | ||
|
||
// Frequently referenced definition of `table` in all test cases among `admin pause test cases` | ||
const adminPauseTestTable string = "t_user" | ||
const adminPauseTestTableStmt string = `CREATE TABLE if not exists ` + adminPauseTestTable + ` ( | ||
id int(11) NOT NULL AUTO_INCREMENT, | ||
tenant varchar(128) NOT NULL, | ||
name varchar(128) NOT NULL, | ||
age int(11) NOT NULL, | ||
province varchar(32) NOT NULL DEFAULT '', | ||
city varchar(32) NOT NULL DEFAULT '', | ||
phone varchar(16) NOT NULL DEFAULT '', | ||
created_time datetime NOT NULL, | ||
updated_time datetime NOT NULL | ||
);` | ||
|
||
const adminPauseTestPartitionTable string = "t_user_partition" | ||
const adminPauseTestPartitionTableStmt string = `CREATE TABLE if not exists ` + adminPauseTestPartitionTable + ` ( | ||
id int(11) NOT NULL AUTO_INCREMENT, | ||
tenant varchar(128) NOT NULL, | ||
name varchar(128) NOT NULL, | ||
age int(11) NOT NULL, | ||
province varchar(32) NOT NULL DEFAULT '', | ||
city varchar(32) NOT NULL DEFAULT '', | ||
phone varchar(16) NOT NULL DEFAULT '', | ||
created_time datetime NOT NULL, | ||
updated_time datetime NOT NULL | ||
) partition by range( age ) ( | ||
partition p0 values less than (20), | ||
partition p1 values less than (40), | ||
partition p2 values less than (60), | ||
partition p3 values less than (80), | ||
partition p4 values less than (100), | ||
partition p5 values less than (120), | ||
partition p6 values less than (160));` | ||
|
||
func generateString(letterRunes []rune, length int) (string, error) { | ||
b := make([]rune, length) | ||
for i := range b { | ||
b[i] = letterRunes[rand.Intn(len(letterRunes))] | ||
} | ||
return string(b), nil | ||
} | ||
|
||
func generateName(length int) (string, error) { | ||
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") | ||
return generateString(letterRunes, length) | ||
} | ||
|
||
func generatePhone(length int) (string, error) { | ||
var numberRunes = []rune("0123456789") | ||
return generateString(numberRunes, length) | ||
} | ||
|
||
func (tu *TestTableUser) generateAttributes(id int) (err error) { | ||
tu.id = id // keep the linter quiet | ||
tu.tenant, err = generateName(rand.Intn(127)) | ||
if err != nil { | ||
return err | ||
} | ||
tu.name, err = generateName(rand.Intn(127)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
tu.age = rand.Intn(AgeMax) | ||
|
||
tu.province, err = generateName(rand.Intn(32)) | ||
if err != nil { | ||
return err | ||
} | ||
tu.city, err = generateName(rand.Intn(32)) | ||
if err != nil { | ||
return err | ||
} | ||
tu.phone, err = generatePhone(14) | ||
if err != nil { | ||
return err | ||
} | ||
tu.createdTime = time.Now() | ||
tu.updatedTime = time.Now() | ||
|
||
return nil | ||
} | ||
|
||
func (tu *TestTableUser) insertStmt(tableName string) string { | ||
return fmt.Sprintf("INSERT INTO %s(tenant, name, age, province, city, phone, created_time, updated_time) "+ | ||
"VALUES ('%s', '%s', %d, '%s', '%s', '%s', '%s', '%s')", | ||
tableName, tu.tenant, tu.name, tu.age, tu.province, tu.city, tu.phone, tu.createdTime, tu.updatedTime) | ||
} | ||
|
||
func generateTblUser(tk *testkit.TestKit, rowCount int) error { | ||
tk.MustExec(adminPauseTestTableStmt) | ||
|
||
tu := &TestTableUser{} | ||
for idx := 0; idx < rowCount; { | ||
_ = tu.generateAttributes(idx) | ||
tk.MustExec(tu.insertStmt(adminPauseTestTable)) | ||
|
||
idx++ | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func generateTblUserParition(tk *testkit.TestKit, rowCount int) error { | ||
tk.MustExec(adminPauseTestPartitionTableStmt) | ||
|
||
tu := &TestTableUser{} | ||
for idx := 0; idx < rowCount; { | ||
_ = tu.generateAttributes(idx) | ||
tk.MustExec(tu.insertStmt(adminPauseTestPartitionTable)) | ||
|
||
idx++ | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.