Skip to content

Commit

Permalink
ddl: migrate test-infra to testify for ddl.testDBSuite6 (pingcap#32973)
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>

Co-authored-by: Ti Chi Robot <[email protected]>
  • Loading branch information
tisonkun and ti-chi-bot authored Mar 9, 2022
1 parent 2caa7ec commit 8711535
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 51 deletions.
51 changes: 0 additions & 51 deletions ddl/db_legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ var _ = Suite(&testDBSuite2{&testDBSuite{}})
var _ = Suite(&testDBSuite3{&testDBSuite{}})
var _ = Suite(&testDBSuite4{&testDBSuite{}})
var _ = Suite(&testDBSuite5{&testDBSuite{}})
var _ = SerialSuites(&testDBSuite6{&testDBSuite{}})
var _ = Suite(&testDBSuite7{&testDBSuite{}})
var _ = Suite(&testDBSuite8{&testDBSuite{}})
var _ = SerialSuites(&testSerialDBSuite{&testDBSuite{}})
Expand Down Expand Up @@ -159,7 +158,6 @@ type testDBSuite2 struct{ *testDBSuite }
type testDBSuite3 struct{ *testDBSuite }
type testDBSuite4 struct{ *testDBSuite }
type testDBSuite5 struct{ *testDBSuite }
type testDBSuite6 struct{ *testDBSuite }
type testDBSuite7 struct{ *testDBSuite }
type testDBSuite8 struct{ *testDBSuite }
type testSerialDBSuite struct{ *testDBSuite }
Expand Down Expand Up @@ -821,26 +819,6 @@ func (s *testDBSuite5) TestAddMultiColumnsIndex(c *C) {
tk.MustExec("admin check table test")
}

func (s *testDBSuite6) TestAddMultiColumnsIndexClusterIndex(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("drop database if exists test_add_multi_col_index_clustered;")
tk.MustExec("create database test_add_multi_col_index_clustered;")
tk.MustExec("use test_add_multi_col_index_clustered;")

tk.Se.GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn
tk.MustExec("create table t (a int, b varchar(10), c int, primary key (a, b));")
tk.MustExec("insert into t values (1, '1', 1), (2, '2', NULL), (3, '3', 3);")
tk.MustExec("create index idx on t (a, c);")

tk.MustExec("admin check index t idx;")
tk.MustExec("admin check table t;")

tk.MustExec("insert into t values (5, '5', 5), (6, '6', NULL);")

tk.MustExec("admin check index t idx;")
tk.MustExec("admin check table t;")
}

// TestCancelAddTableAndDropTablePartition tests cancel ddl job which type is add/drop table partition.
func (s *testDBSuite1) TestCancelAddTableAndDropTablePartition(c *C) {
tk := testkit.NewTestKit(c, s.store)
Expand Down Expand Up @@ -3694,17 +3672,6 @@ func (s *testDBSuite5) TestAlterCheck(c *C) {
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|8231|ALTER CHECK is not supported"))
}

func (s *testDBSuite6) TestDropCheck(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use " + s.schemaName)
tk.MustExec("drop table if exists drop_check")
tk.MustExec("create table drop_check (pk int primary key)")
defer tk.MustExec("drop table if exists drop_check")
tk.MustExec("alter table drop_check drop check crcn")
c.Assert(tk.Se.GetSessionVars().StmtCtx.WarningCount(), Equals, uint16(1))
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|8231|DROP CHECK is not supported"))
}

func (s *testDBSuite7) TestAddConstraintCheck(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use " + s.schemaName)
Expand All @@ -3729,24 +3696,6 @@ func (s *testDBSuite7) TestCreateTableIngoreCheckConstraint(c *C) {
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
}

func (s *testDBSuite6) TestAlterOrderBy(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use " + s.schemaName)
tk.MustExec("create table ob (pk int primary key, c int default 1, c1 int default 1, KEY cl(c1))")

// Test order by with primary key
tk.MustExec("alter table ob order by c")
c.Assert(tk.Se.GetSessionVars().StmtCtx.WarningCount(), Equals, uint16(1))
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1105|ORDER BY ignored as there is a user-defined clustered index in the table 'ob'"))

// Test order by with no primary key
tk.MustExec("drop table if exists ob")
tk.MustExec("create table ob (c int default 1, c1 int default 1, KEY cl(c1))")
tk.MustExec("alter table ob order by c")
c.Assert(tk.Se.GetSessionVars().StmtCtx.WarningCount(), Equals, uint16(0))
tk.MustExec("drop table if exists ob")
}

func (s *testSerialDBSuite) TestDDLJobErrorCount(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
35 changes: 35 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,38 @@ func TestIssue23473(t *testing.T) {
tbl := tk.GetTableByName("test", "t_23473")
require.True(t, mysql.HasNoDefaultValueFlag(tbl.Cols()[0].Flag))
}

func TestDropCheck(t *testing.T) {
store, clean := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists drop_check")
tk.MustExec("create table drop_check (pk int primary key)")
defer tk.MustExec("drop table if exists drop_check")
tk.MustExec("alter table drop_check drop check crcn")
require.Equal(t, uint16(1), tk.Session().GetSessionVars().StmtCtx.WarningCount())
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|8231|DROP CHECK is not supported"))
}

func TestAlterOrderBy(t *testing.T) {
store, clean := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table ob (pk int primary key, c int default 1, c1 int default 1, KEY cl(c1))")

// Test order by with primary key
tk.MustExec("alter table ob order by c")
require.Equal(t, uint16(1), tk.Session().GetSessionVars().StmtCtx.WarningCount())
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1105|ORDER BY ignored as there is a user-defined clustered index in the table 'ob'"))

// Test order by with no primary key
tk.MustExec("drop table if exists ob")
tk.MustExec("create table ob (c int default 1, c1 int default 1, KEY cl(c1))")
tk.MustExec("alter table ob order by c")
require.Equal(t, uint16(0), tk.Session().GetSessionVars().StmtCtx.WarningCount())
tk.MustExec("drop table if exists ob")
}
22 changes: 22 additions & 0 deletions ddl/index_modify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1285,3 +1285,25 @@ LOOP:
checkDelRangeAdded(tk, jobIDExt.jobID, indexID)
tk.MustExec("drop table test_drop_index")
}

func TestAddMultiColumnsIndexClusterIndex(t *testing.T) {
store, clean := testkit.CreateMockStoreWithSchemaLease(t, indexModifyLease)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("drop database if exists test_add_multi_col_index_clustered;")
tk.MustExec("create database test_add_multi_col_index_clustered;")
tk.MustExec("use test_add_multi_col_index_clustered;")

tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn
tk.MustExec("create table t (a int, b varchar(10), c int, primary key (a, b));")
tk.MustExec("insert into t values (1, '1', 1), (2, '2', NULL), (3, '3', 3);")
tk.MustExec("create index idx on t (a, c);")

tk.MustExec("admin check index t idx;")
tk.MustExec("admin check table t;")

tk.MustExec("insert into t values (5, '5', 5), (6, '6', NULL);")

tk.MustExec("admin check index t idx;")
tk.MustExec("admin check table t;")
}

0 comments on commit 8711535

Please sign in to comment.