Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: speed up tests #12888

Merged
merged 7 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func setupIntegrationSuite(s *testIntegrationSuite, c *C) {
s.lease = 50 * time.Millisecond
ddl.WaitTimeWhenErrorOccured = 0

cfg := config.GetGlobalConfig()
newCfg := *cfg
newCfg.Log.SlowThreshold = 10000
config.StoreGlobalConfig(&newCfg)

s.cluster = mocktikv.NewCluster()
mocktikv.BootstrapWithSingleStore(s.cluster)
s.mvccStore = mocktikv.MustNewMVCCStore()
Expand Down
4 changes: 1 addition & 3 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1248,9 +1248,7 @@ func (s *testIntegrationSuite2) TestPartitionCancelAddIndex(c *C) {
base := defaultBatchSize * 2
count := base
// add some rows
for i := 0; i < count; i++ {
tk.MustExec("insert into t1 values (?, ?, ?)", i, i, i)
}
batchInsert(s.tk, "t1", 0, count)

var checkErr error
var c3IdxInfo *model.IndexInfo
Expand Down
39 changes: 27 additions & 12 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func setUpSuite(s *testDBSuite, c *C) {
cfg := config.GetGlobalConfig()
newCfg := *cfg
newCfg.EnableTableLock = true
newCfg.Log.SlowThreshold = 10000
config.StoreGlobalConfig(&newCfg)

s.cluster = mocktikv.NewCluster()
Expand Down Expand Up @@ -225,6 +226,17 @@ func backgroundExec(s kv.Storage, sql string, done chan error) {
done <- errors.Trace(err)
}

func batchInsert(tk *testkit.TestKit, tbl string, start, end int) {
dml := fmt.Sprintf("insert into %s values", tbl)
zimulala marked this conversation as resolved.
Show resolved Hide resolved
for i := start; i < end; i++ {
dml += fmt.Sprintf("(%d, %d, %d)", i, i, i)
if i != end-1 {
dml += ","
}
}
tk.MustExec(dml)
}

func (s *testDBSuite2) TestAddUniqueIndexRollback(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.mustExec(c, "use test_db")
Expand All @@ -234,9 +246,7 @@ func (s *testDBSuite2) TestAddUniqueIndexRollback(c *C) {
base := defaultBatchSize * 2
count := base
// add some rows
for i := 0; i < count; i++ {
s.mustExec(c, "insert into t1 values (?, ?, ?)", i, i, i)
}
batchInsert(s.tk, "t1", 0, count)
// add some duplicate rows
for i := count - 10; i < count; i++ {
s.mustExec(c, "insert into t1 values (?, ?, ?)", i+10, i, i)
Expand Down Expand Up @@ -1330,9 +1340,7 @@ func (s *testDBSuite) testAddColumn(c *C) {

num := defaultBatchSize + 10
// add some rows
for i := 0; i < num; i++ {
s.mustExec(c, "insert into t2 values (?, ?, ?)", i, i, i)
}
batchInsert(s.tk, "t2", 0, num)

testddlutil.SessionExecInGoroutine(c, s.store, "alter table t2 add column c4 int default -1", done)

Expand Down Expand Up @@ -1519,15 +1527,22 @@ func (s *testDBSuite2) TestDropColumn(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("create database drop_col_db")
s.tk.MustExec("use drop_col_db")
s.tk.MustExec("create table t2 (c1 int, c2 int, c3 int)")
num := 50
num := 25
multiDDL := make([]string, 0, num)
sql := "create table t2 (c1 int, c2 int, c3 int, "
for i := 4; i < 4+num; i++ {
multiDDL = append(multiDDL, fmt.Sprintf("alter table t2 drop column c%d", i))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that means dropping the column sequentially, maybe more disorderedly.


if i != 3+num {
sql += fmt.Sprintf("c%d int, ", i)
} else {
sql += fmt.Sprintf("c%d int)", i)
}
}
s.tk.MustExec(sql)
dmlDone := make(chan error, num)
zimulala marked this conversation as resolved.
Show resolved Hide resolved
ddlDone := make(chan error, num)

multiDDL := make([]string, 0, num)
for i := 0; i < num/2; i++ {
multiDDL = append(multiDDL, "alter table t2 add column c4 int", "alter table t2 drop column c4")
}
testddlutil.ExecMultiSQLInGoroutine(c, s.store, "drop_col_db", multiDDL, ddlDone)
for i := 0; i < num; i++ {
testddlutil.ExecMultiSQLInGoroutine(c, s.store, "drop_col_db", []string{"insert into t2 set c1 = 1, c2 = 1, c3 = 1, c4 = 1"}, dmlDone)
zimulala marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
17 changes: 13 additions & 4 deletions ddl/failtest/fail_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,17 @@ func (s *testFailDBSuite) TestGenGlobalIDFail(c *C) {
tk.MustExec("admin check table t2")
}

func batchInsert(tk *testkit.TestKit, tbl string, start, end int) {
dml := fmt.Sprintf("insert into %s values", tbl)
for i := start; i < end; i++ {
dml += fmt.Sprintf("(%d, %d, %d)", i, i, i)
if i != end-1 {
dml += ","
}
}
tk.MustExec(dml)
}

func (s *testFailDBSuite) TestAddIndexWorkerNum(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("create database if not exists test_db")
Expand All @@ -334,11 +345,9 @@ func (s *testFailDBSuite) TestAddIndexWorkerNum(c *C) {

done := make(chan error, 1)
start := -10
num := 4096
// first add some rows
for i := start; i < num; i++ {
sql := fmt.Sprintf("insert into test_add_index values (%d, %d, %d)", i, i, i)
tk.MustExec(sql)
for i := start; i < 4090; i += 100 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually 4100 records are inserted, does it matter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start is -10, so I think 4090 is OK.

batchInsert(tk, "test_add_index", i, i+100)
}

is := s.dom.InfoSchema()
Expand Down