Skip to content

Commit

Permalink
test: stable TestTransactionWithWriteOnlyColumn (#22226)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiwei committed Jan 7, 2021
1 parent 6e98d18 commit 18d3135
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (s *testSerialDBSuite) TestAddExpressionIndexRollback(c *C) {
_, checkErr = tk1.Exec("use test_db")

d := s.dom.DDL()
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: s.dom}
var currJob *model.Job
ctx := mock.NewContext()
ctx.Store = s.store
Expand Down Expand Up @@ -447,7 +447,7 @@ LOOP:
func (s *testDBSuite5) TestCancelAddPrimaryKey(c *C) {
idxName := "primary"
addIdxSQL := "alter table t1 add primary key idx_c2 (c2);"
testCancelAddIndex(c, s.store, s.dom.DDL(), s.lease, idxName, addIdxSQL, "")
testCancelAddIndex(c, s.store, s.dom.DDL(), s.lease, idxName, addIdxSQL, "", s.dom)

// Check the column's flag when the "add primary key" failed.
tk := testkit.NewTestKit(c, s.store)
Expand All @@ -463,14 +463,14 @@ func (s *testDBSuite5) TestCancelAddPrimaryKey(c *C) {
func (s *testDBSuite3) TestCancelAddIndex(c *C) {
idxName := "c3_index "
addIdxSQL := "create unique index c3_index on t1 (c3)"
testCancelAddIndex(c, s.store, s.dom.DDL(), s.lease, idxName, addIdxSQL, "")
testCancelAddIndex(c, s.store, s.dom.DDL(), s.lease, idxName, addIdxSQL, "", s.dom)

tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test_db")
tk.MustExec("drop table t1")
}

func testCancelAddIndex(c *C, store kv.Storage, d ddl.DDL, lease time.Duration, idxName, addIdxSQL, sqlModeSQL string) {
func testCancelAddIndex(c *C, store kv.Storage, d ddl.DDL, lease time.Duration, idxName, addIdxSQL, sqlModeSQL string, dom *domain.Domain) {
tk := testkit.NewTestKit(c, store)
tk.MustExec("use test_db")
tk.MustExec("drop table if exists t1")
Expand All @@ -492,7 +492,7 @@ func testCancelAddIndex(c *C, store kv.Storage, d ddl.DDL, lease time.Duration,
}

var c3IdxInfo *model.IndexInfo
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: dom}
originBatchSize := tk.MustQuery("select @@global.tidb_ddl_reorg_batch_size")
// Set batch size to lower try to slow down add-index reorganization, This if for hook to cancel this ddl job.
tk.MustExec("set @@global.tidb_ddl_reorg_batch_size = 32")
Expand Down Expand Up @@ -558,7 +558,7 @@ func (s *testDBSuite4) TestCancelAddIndex1(c *C) {
}

var checkErr error
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: s.dom}
hook.OnJobRunBeforeExported = func(job *model.Job) {
if job.Type == model.ActionAddIndex && job.State == model.JobStateRunning && job.SchemaState == model.StateWriteReorganization && job.SnapshotVer == 0 {
jobIDs := []int64{job.ID}
Expand Down Expand Up @@ -612,19 +612,19 @@ func (s *testDBSuite4) TestCancelDropPrimaryKey(c *C) {
idxName := "primary"
addIdxSQL := "alter table t add primary key idx_c2 (c2);"
dropIdxSQL := "alter table t drop primary key;"
testCancelDropIndex(c, s.store, s.dom.DDL(), idxName, addIdxSQL, dropIdxSQL)
testCancelDropIndex(c, s.store, s.dom.DDL(), idxName, addIdxSQL, dropIdxSQL, s.dom)
}

// TestCancelDropIndex tests cancel ddl job which type is drop index.
func (s *testDBSuite5) TestCancelDropIndex(c *C) {
idxName := "idx_c2"
addIdxSQL := "alter table t add index idx_c2 (c2);"
dropIdxSQL := "alter table t drop index idx_c2;"
testCancelDropIndex(c, s.store, s.dom.DDL(), idxName, addIdxSQL, dropIdxSQL)
testCancelDropIndex(c, s.store, s.dom.DDL(), idxName, addIdxSQL, dropIdxSQL, s.dom)
}

// testCancelDropIndex tests cancel ddl job which type is drop index.
func testCancelDropIndex(c *C, store kv.Storage, d ddl.DDL, idxName, addIdxSQL, dropIdxSQL string) {
func testCancelDropIndex(c *C, store kv.Storage, d ddl.DDL, idxName, addIdxSQL, dropIdxSQL string, dom *domain.Domain) {
tk := testkit.NewTestKit(c, store)
tk.MustExec("use test_db")
tk.MustExec("drop table if exists t")
Expand All @@ -647,7 +647,7 @@ func testCancelDropIndex(c *C, store kv.Storage, d ddl.DDL, idxName, addIdxSQL,
{true, model.JobStateRunning, model.StateDeleteReorganization, false},
}
var checkErr error
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: dom}
var jobID int64
testCase := &testCases[0]
hook.OnJobRunBeforeExported = func(job *model.Job) {
Expand Down Expand Up @@ -722,7 +722,7 @@ func (s *testDBSuite5) TestCancelTruncateTable(c *C) {
s.mustExec(tk, c, "create table t(c1 int, c2 int)")
defer s.mustExec(tk, c, "drop table t;")
var checkErr error
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: s.dom}
hook.OnJobRunBeforeExported = func(job *model.Job) {
if job.Type == model.ActionTruncateTable && job.State == model.JobStateNone {
jobIDs := []int64{job.ID}
Expand Down Expand Up @@ -765,7 +765,7 @@ func (s *testDBSuite5) TestParallelDropSchemaAndDropTable(c *C) {
s.mustExec(tk, c, "use test_drop_schema_table")
s.mustExec(tk, c, "create table t(c1 int, c2 int)")
var checkErr error
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: s.dom}
dbInfo := testGetSchemaByName(c, tk.Se, "test_drop_schema_table")
done := false
var wg sync.WaitGroup
Expand Down Expand Up @@ -827,7 +827,7 @@ func (s *testDBSuite1) TestCancelRenameIndex(c *C) {
}
s.mustExec(tk, c, "alter table t add index idx_c2(c2)")
var checkErr error
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: s.dom}
hook.OnJobRunBeforeExported = func(job *model.Job) {
if job.Type == model.ActionRenameIndex && job.State == model.JobStateNone {
jobIDs := []int64{job.ID}
Expand Down Expand Up @@ -894,7 +894,7 @@ func (s *testDBSuite2) TestCancelDropTableAndSchema(c *C) {
{true, model.ActionDropSchema, model.JobStateRunning, model.StateDeleteOnly, false},
}
var checkErr error
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: s.dom}
var jobID int64
testCase := &testCases[0]
s.mustExec(tk, c, "create database if not exists test_drop_db")
Expand Down Expand Up @@ -1336,7 +1336,7 @@ func (s *testDBSuite1) TestCancelAddTableAndDropTablePartition(c *C) {
{model.ActionAddTablePartition, model.JobStateRunning, model.StateReplicaOnly, true},
}
var checkErr error
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: s.dom}
testCase := &testCases[0]
var jobID int64
hook.OnJobRunBeforeExported = func(job *model.Job) {
Expand Down Expand Up @@ -1507,7 +1507,7 @@ func (s *testDBSuite3) TestCancelDropColumn(c *C) {
{true, model.JobStateRunning, model.StateDeleteReorganization, false},
}
var checkErr error
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: s.dom}
var jobID int64
testCase := &testCases[0]
hook.OnJobRunBeforeExported = func(job *model.Job) {
Expand Down Expand Up @@ -1614,7 +1614,7 @@ func (s *testDBSuite3) TestCancelDropColumns(c *C) {
{true, model.JobStateRunning, model.StateDeleteReorganization, false},
}
var checkErr error
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: s.dom}
var jobID int64
testCase := &testCases[0]
hook.OnJobRunBeforeExported = func(job *model.Job) {
Expand Down Expand Up @@ -2465,7 +2465,7 @@ func (s *testSerialDBSuite) TestCreateTableWithLike2(c *C) {

tbl1 := testGetTableByName(c, s.s, "test_db", "t1")
doneCh := make(chan error, 2)
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: s.dom}
var onceChecker sync.Map
hook.OnJobRunBeforeExported = func(job *model.Job) {
if job.Type != model.ActionAddColumn && job.Type != model.ActionDropColumn &&
Expand Down Expand Up @@ -2745,7 +2745,7 @@ func (s *testSerialDBSuite) TestRepairTable(c *C) {
// Repaired tableInfo has been filtered by `domain.InfoSchema()`, so get it in repairInfo.
originTableInfo, _ := domainutil.RepairInfo.GetRepairedTableInfoByTableName("test", "origin")

hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: s.dom}
var repairErr error
hook.OnJobRunBeforeExported = func(job *model.Job) {
if job.Type != model.ActionRepairTable {
Expand Down Expand Up @@ -3832,7 +3832,7 @@ func (s *testDBSuite5) TestModifyColumnRollBack(c *C) {

var c2 *table.Column
var checkErr error
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: s.dom}
hook.OnJobUpdatedExported = func(job *model.Job) {
if checkErr != nil {
return
Expand Down Expand Up @@ -3930,7 +3930,7 @@ func (s *testSerialDBSuite) TestModifyColumnnReorgInfo(c *C) {
defer s.dom.DDL().(ddl.DDLForTest).SetHook(originalHook)

// Check insert null before job first update.
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: s.dom}
var checkErr error
var currJob *model.Job
var elements []*meta.Element
Expand Down Expand Up @@ -4155,7 +4155,7 @@ func testModifyColumnNullToNotNull(c *C, s *testDBSuite, enableChangeColumnType

// Check insert null before job first update.
times := 0
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: s.dom}
tk.MustExec("delete from t1")
var checkErr error
hook.OnJobRunBeforeExported = func(job *model.Job) {
Expand Down Expand Up @@ -4284,7 +4284,7 @@ func (s *testDBSuite3) TestTransactionWithWriteOnlyColumn(c *C) {

originHook := s.dom.DDL().GetHook()
defer s.dom.DDL().(ddl.DDLForTest).SetHook(originHook)
hook := &ddl.TestDDLCallback{}
hook := &ddl.TestDDLCallback{Do: s.dom}
var checkErr error
hook.OnJobRunBeforeExported = func(job *model.Job) {
if checkErr != nil {
Expand Down

0 comments on commit 18d3135

Please sign in to comment.