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: split some tests into new package #40758

Merged
merged 5 commits into from
Jan 29, 2023
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
4 changes: 1 addition & 3 deletions ddl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ go_test(
srcs = [
"attributes_sql_test.go",
"backfilling_test.go",
"callback_test.go",
"cancel_test.go",
"cluster_test.go",
"column_change_test.go",
Expand All @@ -176,7 +175,6 @@ go_test(
"foreign_key_test.go",
"index_change_test.go",
"index_cop_test.go",
"index_merge_tmp_test.go",
"index_modify_test.go",
"integration_test.go",
"job_table_test.go",
Expand Down Expand Up @@ -210,7 +208,7 @@ go_test(
deps = [
"//autoid_service",
"//config",
"//ddl/ingest",
"//ddl/internal/callback",
"//ddl/placement",
"//ddl/resourcegroup",
"//ddl/schematracker",
Expand Down
7 changes: 4 additions & 3 deletions ddl/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/internal/callback"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/testkit"
Expand Down Expand Up @@ -264,7 +265,7 @@ func TestCancel(t *testing.T) {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/mockBackfillSlow"))
}()

hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
i := atomicutil.NewInt64(0)
cancel := atomicutil.NewBool(false)
cancelResult := atomicutil.NewBool(false)
Expand All @@ -282,12 +283,12 @@ func TestCancel(t *testing.T) {
}
dom.DDL().SetHook(hook.Clone())

restHook := func(h *ddl.TestDDLCallback) {
restHook := func(h *callback.TestDDLCallback) {
h.OnJobRunBeforeExported = nil
h.OnJobUpdatedExported.Store(nil)
dom.DDL().SetHook(h.Clone())
}
registHook := func(h *ddl.TestDDLCallback, onJobRunBefore bool) {
registHook := func(h *callback.TestDDLCallback, onJobRunBefore bool) {
if onJobRunBefore {
h.OnJobRunBeforeExported = hookFunc
} else {
Expand Down
7 changes: 4 additions & 3 deletions ddl/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/internal/callback"
"github.com/pingcap/tidb/domain/infosync"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/meta"
Expand Down Expand Up @@ -84,7 +85,7 @@ func TestFlashbackCloseAndResetPDSchedule(t *testing.T) {
defer resetGC()
tk.MustExec(fmt.Sprintf(safePointSQL, timeBeforeDrop))

hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
hook.OnJobRunBeforeExported = func(job *model.Job) {
assert.Equal(t, model.ActionFlashbackCluster, job.Type)
if job.SchemaState == model.StateWriteReorganization {
Expand Down Expand Up @@ -136,7 +137,7 @@ func TestAddDDLDuringFlashback(t *testing.T) {
defer resetGC()
tk.MustExec(fmt.Sprintf(safePointSQL, timeBeforeDrop))

hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
hook.OnJobRunBeforeExported = func(job *model.Job) {
assert.Equal(t, model.ActionFlashbackCluster, job.Type)
if job.SchemaState == model.StateWriteOnly {
Expand Down Expand Up @@ -175,7 +176,7 @@ func TestGlobalVariablesOnFlashback(t *testing.T) {
defer resetGC()
tk.MustExec(fmt.Sprintf(safePointSQL, timeBeforeDrop))

hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
hook.OnJobRunBeforeExported = func(job *model.Job) {
assert.Equal(t, model.ActionFlashbackCluster, job.Type)
if job.SchemaState == model.StateWriteReorganization {
Expand Down
7 changes: 4 additions & 3 deletions ddl/column_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/pingcap/errors"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/internal/callback"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/parser/model"
Expand All @@ -48,7 +49,7 @@ func TestColumnAdd(t *testing.T) {
tk.MustExec("insert t values (1, 2);")

d := dom.DDL()
tc := &ddl.TestDDLCallback{Do: dom}
tc := &callback.TestDDLCallback{Do: dom}

ct := testNewContext(store)
// set up hook
Expand Down Expand Up @@ -149,7 +150,7 @@ func TestModifyAutoRandColumnWithMetaKeyChanged(t *testing.T) {
tk.MustExec("create table t (a bigint primary key clustered AUTO_RANDOM(5));")

d := dom.DDL()
tc := &ddl.TestDDLCallback{Do: dom}
tc := &callback.TestDDLCallback{Do: dom}

var errCount int32 = 3
var genAutoRandErr error
Expand Down Expand Up @@ -457,7 +458,7 @@ func TestIssue40135(t *testing.T) {

tk.MustExec("CREATE TABLE t40135 ( a tinyint DEFAULT NULL, b varchar(32) DEFAULT 'md') PARTITION BY HASH (a) PARTITIONS 2")
one := true
hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
var checkErr error
hook.OnJobRunBeforeExported = func(job *model.Job) {
if one {
Expand Down
8 changes: 4 additions & 4 deletions ddl/column_modify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"time"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/internal/callback"
testddlutil "github.com/pingcap/tidb/ddl/testutil"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/errno"
Expand Down Expand Up @@ -664,7 +664,7 @@ func TestTransactionWithWriteOnlyColumn(t *testing.T) {
},
}

hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
var checkErr error
hook.OnJobRunBeforeExported = func(job *model.Job) {
if checkErr != nil {
Expand Down Expand Up @@ -872,7 +872,7 @@ func TestAddGeneratedColumnAndInsert(t *testing.T) {
tk1.MustExec("use test")

d := dom.DDL()
hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
ctx := mock.NewContext()
ctx.Store = store
times := 0
Expand Down Expand Up @@ -916,7 +916,7 @@ func TestColumnTypeChangeGenUniqueChangingName(t *testing.T) {
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")

hook := &ddl.TestDDLCallback{}
hook := &callback.TestDDLCallback{}
var checkErr error
assertChangingColName := "_col$_c2_0"
assertChangingIdxName := "_idx$_idx_0"
Expand Down
14 changes: 7 additions & 7 deletions ddl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"testing"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/internal/callback"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/model"
Expand Down Expand Up @@ -672,7 +672,7 @@ func TestAddColumn(t *testing.T) {

checkOK := false

tc := &ddl.TestDDLCallback{Do: dom}
tc := &callback.TestDDLCallback{Do: dom}
onJobUpdatedExportedFunc := func(job *model.Job) {
if checkOK {
return
Expand Down Expand Up @@ -740,7 +740,7 @@ func TestAddColumns(t *testing.T) {
err = txn.Commit(context.Background())
require.NoError(t, err)

tc := &ddl.TestDDLCallback{Do: dom}
tc := &callback.TestDDLCallback{Do: dom}
onJobUpdatedExportedFunc := func(job *model.Job) {
mu.Lock()
defer mu.Unlock()
Expand Down Expand Up @@ -810,7 +810,7 @@ func TestDropColumnInColumnTest(t *testing.T) {
var mu sync.Mutex

d := dom.DDL()
tc := &ddl.TestDDLCallback{Do: dom}
tc := &callback.TestDDLCallback{Do: dom}
onJobUpdatedExportedFunc := func(job *model.Job) {
mu.Lock()
defer mu.Unlock()
Expand Down Expand Up @@ -872,7 +872,7 @@ func TestDropColumns(t *testing.T) {
var mu sync.Mutex

d := dom.DDL()
tc := &ddl.TestDDLCallback{Do: dom}
tc := &callback.TestDDLCallback{Do: dom}
onJobUpdatedExportedFunc := func(job *model.Job) {
mu.Lock()
defer mu.Unlock()
Expand Down Expand Up @@ -998,7 +998,7 @@ func TestWriteDataWriteOnlyMode(t *testing.T) {
originalCallback := dom.DDL().GetHook()
defer dom.DDL().SetHook(originalCallback)

hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
hook.OnJobRunBeforeExported = func(job *model.Job) {
if job.SchemaState != model.StateWriteOnly {
return
Expand All @@ -1009,7 +1009,7 @@ func TestWriteDataWriteOnlyMode(t *testing.T) {
dom.DDL().SetHook(hook)
tk.MustExec("alter table t change column `col1` `col1` varchar(20)")

hook = &ddl.TestDDLCallback{Do: dom}
hook = &callback.TestDDLCallback{Do: dom}
hook.OnJobRunBeforeExported = func(job *model.Job) {
if job.SchemaState != model.StateWriteOnly {
return
Expand Down
21 changes: 11 additions & 10 deletions ddl/column_type_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/internal/callback"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/model"
Expand Down Expand Up @@ -121,7 +122,7 @@ func TestColumnTypeChangeStateBetweenInteger(t *testing.T) {
require.Equal(t, 2, len(tbl.Cols()))
require.NotNil(t, external.GetModifyColumn(t, tk, "test", "t", "c2", false))

hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
var checkErr error
hook.OnJobRunBeforeExported = func(job *model.Job) {
if checkErr != nil {
Expand Down Expand Up @@ -185,7 +186,7 @@ func TestRollbackColumnTypeChangeBetweenInteger(t *testing.T) {
require.Equal(t, 2, len(tbl.Cols()))
require.NotNil(t, external.GetModifyColumn(t, tk, "test", "t", "c2", false))

hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
// Mock roll back at model.StateNone.
customizeHookRollbackAtState(hook, tbl, model.StateNone)
dom.DDL().SetHook(hook)
Expand Down Expand Up @@ -217,7 +218,7 @@ func TestRollbackColumnTypeChangeBetweenInteger(t *testing.T) {
assertRollBackedColUnchanged(t, tk)
}

func customizeHookRollbackAtState(hook *ddl.TestDDLCallback, tbl table.Table, state model.SchemaState) {
func customizeHookRollbackAtState(hook *callback.TestDDLCallback, tbl table.Table, state model.SchemaState) {
hook.OnJobRunBeforeExported = func(job *model.Job) {
if tbl.Meta().ID != job.TableID {
return
Expand Down Expand Up @@ -934,7 +935,7 @@ func TestColumnTypeChangeIgnoreDisplayLength(t *testing.T) {
assertHasAlterWriteReorg := func(tbl table.Table) {
// Restore assertResult to false.
assertResult = false
hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
hook.OnJobRunBeforeExported = func(job *model.Job) {
if tbl.Meta().ID != job.TableID {
return
Expand Down Expand Up @@ -1600,7 +1601,7 @@ func TestChangingColOriginDefaultValue(t *testing.T) {

tbl := external.GetTableByName(t, tk, "test", "t")
originalHook := dom.DDL().GetHook()
hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
var (
once bool
checkErr error
Expand Down Expand Up @@ -1679,7 +1680,7 @@ func TestChangingColOriginDefaultValueAfterAddColAndCastSucc(t *testing.T) {

tbl := external.GetTableByName(t, tk, "test", "t")
originalHook := dom.DDL().GetHook()
hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
var (
once bool
checkErr error
Expand Down Expand Up @@ -1764,7 +1765,7 @@ func TestChangingColOriginDefaultValueAfterAddColAndCastFail(t *testing.T) {

tbl := external.GetTableByName(t, tk, "test", "t")
originalHook := dom.DDL().GetHook()
hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
var checkErr error
hook.OnJobRunBeforeExported = func(job *model.Job) {
if checkErr != nil {
Expand Down Expand Up @@ -1893,7 +1894,7 @@ func TestDDLExitWhenCancelMeetPanic(t *testing.T) {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/mockExceedErrorLimit"))
}()

hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
var jobID int64
hook.OnJobRunBeforeExported = func(job *model.Job) {
if jobID != 0 {
Expand Down Expand Up @@ -1968,7 +1969,7 @@ func TestCancelCTCInReorgStateWillCauseGoroutineLeak(t *testing.T) {
tk.MustExec("insert into ctc_goroutine_leak values(1),(2),(3)")
tbl := external.GetTableByName(t, tk, "test", "ctc_goroutine_leak")

hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
var jobID int64
hook.OnJobRunBeforeExported = func(job *model.Job) {
if jobID != 0 {
Expand Down Expand Up @@ -2210,7 +2211,7 @@ func TestCastDateToTimestampInReorgAttribute(t *testing.T) {
var checkErr1 error
var checkErr2 error

hook := &ddl.TestDDLCallback{Do: dom}
hook := &callback.TestDDLCallback{Do: dom}
hook.OnJobRunBeforeExported = func(job *model.Job) {
if checkErr1 != nil || checkErr2 != nil || tbl.Meta().ID != job.TableID {
return
Expand Down
Loading