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

*: improve TestColumnAdd for concurrency ddl #33660

Merged
merged 8 commits into from
Apr 2, 2022
21 changes: 10 additions & 11 deletions ddl/column_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/testkit/external"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/mock"
"github.com/stretchr/testify/require"
Expand All @@ -41,6 +42,7 @@ func TestColumnAdd(t *testing.T) {
defer clean()
ddl.SetWaitTimeWhenErrorOccurred(1 * time.Microsecond)
tk := testkit.NewTestKit(t, store)
internal := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t (c1 int, c2 int);")
tk.MustExec("insert t values (1, 2);")
Expand Down Expand Up @@ -86,19 +88,16 @@ func TestColumnAdd(t *testing.T) {
checkHistoryJobArgs(t, tk.Session(), jobID, &historyJobArgs{ver: v, tbl: tb.Meta()})

// Drop column.
first = true
tc.OnJobRunBeforeExported = func(job *model.Job) {
if dropCol == nil {
tbl := external.GetTableByName(t, internal, "test", "t")
dropCol = tbl.VisibleCols()[2]
}
}
tc.OnJobUpdatedExported = func(job *model.Job) {
jobID = job.ID
require.NoError(t, dom.Reload())
tbl, exist := dom.InfoSchema().TableByID(job.TableID)
require.True(t, exist)
switch job.SchemaState {
case model.StateNone:
if first {
dropCol = tbl.VisibleCols()[2]
first = false
}
default:
tbl := external.GetTableByName(t, internal, "test", "t")
if job.SchemaState != model.StateNone {
for _, col := range tbl.Cols() {
require.NotEqualf(t, col.ID, dropCol.ID, "column is not dropped")
}
Expand Down