Skip to content

Commit

Permalink
ddl: speed up tests (pingcap#12888)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala authored and XiaTianliang committed Dec 21, 2019
1 parent e1b43fa commit f99db85
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 19 deletions.
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)
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))

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)
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)
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 {
batchInsert(tk, "test_add_index", i, i+100)
}

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

0 comments on commit f99db85

Please sign in to comment.