From 5691ff3d7f84b630376dc3443997313792307d20 Mon Sep 17 00:00:00 2001 From: winkyao Date: Tue, 23 Apr 2019 17:18:58 +0800 Subject: [PATCH] ddl: spead up ddl unit test (#10234) --- ddl/db_integration_test.go | 136 +++++++++++++++++++------------ ddl/db_partition_test.go | 34 ++++---- ddl/db_test.go | 161 +++++++++++++++++++++++-------------- 3 files changed, 204 insertions(+), 127 deletions(-) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 8ab7b9fbdca20..171a5128b27b4 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -46,7 +46,17 @@ import ( "github.com/pingcap/tidb/util/testkit" ) -var _ = Suite(&testIntegrationSuite{}) +var _ = Suite(&testIntegrationSuite1{&testIntegrationSuite{}}) +var _ = Suite(&testIntegrationSuite2{&testIntegrationSuite{}}) +var _ = Suite(&testIntegrationSuite3{&testIntegrationSuite{}}) +var _ = Suite(&testIntegrationSuite4{&testIntegrationSuite{}}) +var _ = Suite(&testIntegrationSuite5{&testIntegrationSuite{}}) +var _ = Suite(&testIntegrationSuite6{&testIntegrationSuite{}}) +var _ = Suite(&testIntegrationSuite7{&testIntegrationSuite{}}) +var _ = Suite(&testIntegrationSuite8{&testIntegrationSuite{}}) +var _ = Suite(&testIntegrationSuite9{&testIntegrationSuite{}}) +var _ = Suite(&testIntegrationSuite10{&testIntegrationSuite{}}) +var _ = Suite(&testIntegrationSuite11{&testIntegrationSuite{}}) type testIntegrationSuite struct { lease time.Duration @@ -58,19 +68,10 @@ type testIntegrationSuite struct { tk *testkit.TestKit } -func (s *testIntegrationSuite) TearDownTest(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - r := tk.MustQuery("show tables") - for _, tb := range r.Rows() { - tableName := tb[0] - tk.MustExec(fmt.Sprintf("drop table %v", tableName)) - } -} - -func (s *testIntegrationSuite) SetUpSuite(c *C) { +func setupIntegrationSuite(s *testIntegrationSuite, c *C) { var err error s.lease = 50 * time.Millisecond + ddl.WaitTimeWhenErrorOccured = 0 s.cluster = mocktikv.NewCluster() mocktikv.BootstrapWithSingleStore(s.cluster) @@ -93,12 +94,47 @@ func (s *testIntegrationSuite) SetUpSuite(c *C) { s.tk = testkit.NewTestKit(c, s.store) } -func (s *testIntegrationSuite) TearDownSuite(c *C) { +func tearDownIntegrationSuiteTest(s *testIntegrationSuite, c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + r := tk.MustQuery("show tables") + for _, tb := range r.Rows() { + tableName := tb[0] + tk.MustExec(fmt.Sprintf("drop table %v", tableName)) + } +} + +func tearDownIntegrationSuite(s *testIntegrationSuite, c *C) { s.dom.Close() s.store.Close() } -func (s *testIntegrationSuite) TestNoZeroDateMode(c *C) { +func (s *testIntegrationSuite) SetUpSuite(c *C) { + setupIntegrationSuite(s, c) +} + +func (s *testIntegrationSuite) TearDownSuite(c *C) { + tearDownIntegrationSuite(s, c) +} + +type testIntegrationSuite1 struct{ *testIntegrationSuite } +type testIntegrationSuite2 struct{ *testIntegrationSuite } + +func (s *testIntegrationSuite2) TearDownTest(c *C) { + tearDownIntegrationSuiteTest(s.testIntegrationSuite, c) +} + +type testIntegrationSuite3 struct{ *testIntegrationSuite } +type testIntegrationSuite4 struct{ *testIntegrationSuite } +type testIntegrationSuite5 struct{ *testIntegrationSuite } +type testIntegrationSuite6 struct{ *testIntegrationSuite } +type testIntegrationSuite7 struct{ *testIntegrationSuite } +type testIntegrationSuite8 struct{ *testIntegrationSuite } +type testIntegrationSuite9 struct{ *testIntegrationSuite } +type testIntegrationSuite10 struct{ *testIntegrationSuite } +type testIntegrationSuite11 struct{ *testIntegrationSuite } + +func (s *testIntegrationSuite6) TestNoZeroDateMode(c *C) { tk := testkit.NewTestKit(c, s.store) defer tk.MustExec("set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';") @@ -112,7 +148,7 @@ func (s *testIntegrationSuite) TestNoZeroDateMode(c *C) { assertErrorCode(c, tk, "create table test_zero_date(a timestamp default 0);", mysql.ErrInvalidDefault) } -func (s *testIntegrationSuite) TestInvalidDefault(c *C) { +func (s *testIntegrationSuite7) TestInvalidDefault(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("USE test;") @@ -127,7 +163,7 @@ func (s *testIntegrationSuite) TestInvalidDefault(c *C) { } // TestInvalidNameWhenCreateTable for issue #3848 -func (s *testIntegrationSuite) TestInvalidNameWhenCreateTable(c *C) { +func (s *testIntegrationSuite8) TestInvalidNameWhenCreateTable(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("USE test;") @@ -146,7 +182,7 @@ func (s *testIntegrationSuite) TestInvalidNameWhenCreateTable(c *C) { } // TestCreateTableIfNotExists for issue #6879 -func (s *testIntegrationSuite) TestCreateTableIfNotExists(c *C) { +func (s *testIntegrationSuite3) TestCreateTableIfNotExists(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("USE test;") @@ -171,7 +207,7 @@ func (s *testIntegrationSuite) TestCreateTableIfNotExists(c *C) { } // for issue #9910 -func (s *testIntegrationSuite) TestCreateTableWithKeyWord(c *C) { +func (s *testIntegrationSuite2) TestCreateTableWithKeyWord(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("USE test;") @@ -180,7 +216,7 @@ func (s *testIntegrationSuite) TestCreateTableWithKeyWord(c *C) { c.Assert(err, IsNil) } -func (s *testIntegrationSuite) TestUniqueKeyNullValue(c *C) { +func (s *testIntegrationSuite1) TestUniqueKeyNullValue(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("USE test") tk.MustExec("create table t(a int primary key, b varchar(255))") @@ -194,7 +230,7 @@ func (s *testIntegrationSuite) TestUniqueKeyNullValue(c *C) { tk.MustExec("admin check index t b") } -func (s *testIntegrationSuite) TestEndIncluded(c *C) { +func (s *testIntegrationSuite4) TestEndIncluded(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("USE test") @@ -208,7 +244,7 @@ func (s *testIntegrationSuite) TestEndIncluded(c *C) { } // TestModifyColumnAfterAddIndex Issue 5134 -func (s *testIntegrationSuite) TestModifyColumnAfterAddIndex(c *C) { +func (s *testIntegrationSuite3) TestModifyColumnAfterAddIndex(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("create table city (city VARCHAR(2) KEY);") @@ -216,7 +252,7 @@ func (s *testIntegrationSuite) TestModifyColumnAfterAddIndex(c *C) { tk.MustExec(`insert into city values ("abc"), ("abd");`) } -func (s *testIntegrationSuite) TestIssue2293(c *C) { +func (s *testIntegrationSuite9) TestIssue2293(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("create table t_issue_2293 (a int)") @@ -226,7 +262,7 @@ func (s *testIntegrationSuite) TestIssue2293(c *C) { tk.MustQuery("select * from t_issue_2293").Check(testkit.Rows("1")) } -func (s *testIntegrationSuite) TestIssue6101(c *C) { +func (s *testIntegrationSuite2) TestIssue6101(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("create table t1 (quantity decimal(2) unsigned);") @@ -242,7 +278,7 @@ func (s *testIntegrationSuite) TestIssue6101(c *C) { tk.MustExec("drop table t1") } -func (s *testIntegrationSuite) TestIssue3833(c *C) { +func (s *testIntegrationSuite4) TestIssue3833(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("create table issue3833 (b char(0))") @@ -251,7 +287,7 @@ func (s *testIntegrationSuite) TestIssue3833(c *C) { assertErrorCode(c, tk, "create table issue3833_2 (b char(0), index (b))", tmysql.ErrWrongKeyColumn) } -func (s *testIntegrationSuite) TestIssue2858And2717(c *C) { +func (s *testIntegrationSuite10) TestIssue2858And2717(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -268,7 +304,7 @@ func (s *testIntegrationSuite) TestIssue2858And2717(c *C) { tk.MustExec(`alter table t_issue_2858_hex alter column a set default 0x321`) } -func (s *testIntegrationSuite) TestIssue4432(c *C) { +func (s *testIntegrationSuite1) TestIssue4432(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -293,7 +329,7 @@ func (s *testIntegrationSuite) TestIssue4432(c *C) { tk.MustExec("drop table tx") } -func (s *testIntegrationSuite) TestMySQLErrorCode(c *C) { +func (s *testIntegrationSuite5) TestMySQLErrorCode(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test_db") @@ -410,7 +446,7 @@ func (s *testIntegrationSuite) TestMySQLErrorCode(c *C) { assertErrorCode(c, tk, sql, tmysql.ErrBadNull) } -func (s *testIntegrationSuite) TestTableDDLWithFloatType(c *C) { +func (s *testIntegrationSuite9) TestTableDDLWithFloatType(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("drop table if exists t") @@ -425,7 +461,7 @@ func (s *testIntegrationSuite) TestTableDDLWithFloatType(c *C) { s.tk.MustExec("drop table t") } -func (s *testIntegrationSuite) TestTableDDLWithTimeType(c *C) { +func (s *testIntegrationSuite10) TestTableDDLWithTimeType(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("drop table if exists t") @@ -448,7 +484,7 @@ func (s *testIntegrationSuite) TestTableDDLWithTimeType(c *C) { s.tk.MustExec("drop table t") } -func (s *testIntegrationSuite) TestUpdateMultipleTable(c *C) { +func (s *testIntegrationSuite2) TestUpdateMultipleTable(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("create database umt_db") tk.MustExec("use umt_db") @@ -507,7 +543,7 @@ func (s *testIntegrationSuite) TestUpdateMultipleTable(c *C) { tk.MustExec("drop database umt_db") } -func (s *testIntegrationSuite) TestNullGeneratedColumn(c *C) { +func (s *testIntegrationSuite7) TestNullGeneratedColumn(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -525,7 +561,7 @@ func (s *testIntegrationSuite) TestNullGeneratedColumn(c *C) { tk.MustExec("drop table t") } -func (s *testIntegrationSuite) TestChangingCharsetToUtf8(c *C) { +func (s *testIntegrationSuite9) TestChangingCharsetToUtf8(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -571,7 +607,7 @@ func (s *testIntegrationSuite) TestChangingCharsetToUtf8(c *C) { c.Assert(err, NotNil) } -func (s *testIntegrationSuite) TestChangingTableCharset(c *C) { +func (s *testIntegrationSuite10) TestChangingTableCharset(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("USE test") @@ -704,7 +740,7 @@ func (s *testIntegrationSuite) TestChangingTableCharset(c *C) { checkCharset() } -func (s *testIntegrationSuite) TestCaseInsensitiveCharsetAndCollate(c *C) { +func (s *testIntegrationSuite7) TestCaseInsensitiveCharsetAndCollate(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("create database if not exists test_charset_collate") @@ -717,7 +753,7 @@ func (s *testIntegrationSuite) TestCaseInsensitiveCharsetAndCollate(c *C) { tk.MustExec("create table t4(id int) ENGINE=InnoDB DEFAULT CHARSET=Utf8mb4 COLLATE=utf8MB4_general_ci;") } -func (s *testIntegrationSuite) TestZeroFillCreateTable(c *C) { +func (s *testIntegrationSuite3) TestZeroFillCreateTable(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("drop table if exists abc;") @@ -742,7 +778,7 @@ func (s *testIntegrationSuite) TestZeroFillCreateTable(c *C) { c.Assert(mysql.HasUnsignedFlag(zCol.Flag), IsTrue) } -func (s *testIntegrationSuite) TestBitDefaultValue(c *C) { +func (s *testIntegrationSuite6) TestBitDefaultValue(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("create table t_bit (c1 bit(10) default 250, c2 int);") @@ -792,7 +828,7 @@ func (s *testIntegrationSuite) TestBitDefaultValue(c *C) { );`) } -func (s *testIntegrationSuite) TestBackwardCompatibility(c *C) { +func (s *testIntegrationSuite5) TestBackwardCompatibility(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("create database if not exists test_backward_compatibility") defer tk.MustExec("drop database test_backward_compatibility") @@ -867,7 +903,7 @@ func (s *testIntegrationSuite) TestBackwardCompatibility(c *C) { tk.MustExec("admin check index t idx_b") } -func (s *testIntegrationSuite) TestMultiRegionGetTableEndHandle(c *C) { +func (s *testIntegrationSuite4) TestMultiRegionGetTableEndHandle(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("drop database if exists test_get_endhandle") tk.MustExec("create database test_get_endhandle") @@ -938,7 +974,7 @@ func (s *testIntegrationSuite) checkGetMaxTableRowID(ctx *testMaxTableRowIDConte c.Assert(maxID, Equals, expectMaxID) } -func (s *testIntegrationSuite) TestGetTableEndHandle(c *C) { +func (s *testIntegrationSuite6) TestGetTableEndHandle(c *C) { // TestGetTableEndHandle test ddl.GetTableMaxRowID method, which will return the max row id of the table. tk := testkit.NewTestKit(c, s.store) tk.MustExec("drop database if exists test_get_endhandle") @@ -1034,7 +1070,7 @@ func (s *testIntegrationSuite) getHistoryDDLJob(id int64) (*model.Job, error) { return job, errors.Trace(err) } -func (s *testIntegrationSuite) TestCreateTableTooLarge(c *C) { +func (s *testIntegrationSuite1) TestCreateTableTooLarge(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") @@ -1056,7 +1092,7 @@ func (s *testIntegrationSuite) TestCreateTableTooLarge(c *C) { atomic.StoreUint32(&ddl.TableColumnCountLimit, originLimit) } -func (s *testIntegrationSuite) TestChangeColumnPosition(c *C) { +func (s *testIntegrationSuite8) TestChangeColumnPosition(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") @@ -1107,7 +1143,7 @@ func (s *testIntegrationSuite) TestChangeColumnPosition(c *C) { c.Assert(createSQL, Equals, strings.Join(exceptedSQL, "\n")) } -func (s *testIntegrationSuite) TestAddIndexAfterAddColumn(c *C) { +func (s *testIntegrationSuite2) TestAddIndexAfterAddColumn(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") @@ -1120,7 +1156,7 @@ func (s *testIntegrationSuite) TestAddIndexAfterAddColumn(c *C) { assertErrorCode(c, s.tk, sql, tmysql.ErrTooManyKeyParts) } -func (s *testIntegrationSuite) TestResolveCharset(c *C) { +func (s *testIntegrationSuite8) TestResolveCharset(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("drop table if exists resolve_charset") @@ -1150,7 +1186,7 @@ func (s *testIntegrationSuite) TestResolveCharset(c *C) { c.Assert(tbl.Meta().Charset, Equals, "binary") } -func (s *testIntegrationSuite) TestAddAnonymousIndex(c *C) { +func (s *testIntegrationSuite2) TestAddAnonymousIndex(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("create table t_anonymous_index (c1 int, c2 int, C3 int)") @@ -1200,7 +1236,7 @@ func (s *testIntegrationSuite) TestAddAnonymousIndex(c *C) { c.Assert(t.Indices()[1].Meta().Name.String(), Equals, "primary_3") } -func (s *testIntegrationSuite) TestAddColumnTooMany(c *C) { +func (s *testIntegrationSuite1) TestAddColumnTooMany(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") count := int(atomic.LoadUint32(&ddl.TableColumnCountLimit) - 1) @@ -1215,7 +1251,7 @@ func (s *testIntegrationSuite) TestAddColumnTooMany(c *C) { assertErrorCode(c, s.tk, alterSQL, tmysql.ErrTooManyFields) } -func (s *testIntegrationSuite) TestAlterColumn(c *C) { +func (s *testIntegrationSuite4) TestAlterColumn(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test_db") @@ -1333,7 +1369,7 @@ func (s *testIntegrationSuite) assertAlterErrorExec(c *C, sql string) { assertErrorCode(c, s.tk, sql, mysql.ErrAlterOperationNotSupportedReason) } -func (s *testIntegrationSuite) TestAlterAlgorithm(c *C) { +func (s *testIntegrationSuite3) TestAlterAlgorithm(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("drop table if exists t, t1") @@ -1397,7 +1433,7 @@ func (s *testIntegrationSuite) TestAlterAlgorithm(c *C) { s.tk.MustExec("alter table t default charset = utf8mb4, ALGORITHM=INSTANT") } -func (s *testIntegrationSuite) TestFulltextIndexIgnore(c *C) { +func (s *testIntegrationSuite5) TestFulltextIndexIgnore(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("drop table if exists t_ft") @@ -1413,7 +1449,7 @@ func (s *testIntegrationSuite) TestFulltextIndexIgnore(c *C) { c.Assert(r.Rows(), HasLen, 0) } -func (s *testIntegrationSuite) TestTreatOldVersionUTF8AsUTF8MB4(c *C) { +func (s *testIntegrationSuite1) TestTreatOldVersionUTF8AsUTF8MB4(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("drop table if exists t") @@ -1548,7 +1584,7 @@ func (s *testIntegrationSuite) TestTreatOldVersionUTF8AsUTF8MB4(c *C) { ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) } -func (s *testIntegrationSuite) TestDefaultValueIsString(c *C) { +func (s *testIntegrationSuite3) TestDefaultValueIsString(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("drop table if exists t") diff --git a/ddl/db_partition_test.go b/ddl/db_partition_test.go index 60e07b6dff99a..3ebab9da7b640 100644 --- a/ddl/db_partition_test.go +++ b/ddl/db_partition_test.go @@ -42,7 +42,7 @@ import ( "github.com/pingcap/tidb/util/testkit" ) -func (s *testIntegrationSuite) TestCreateTableWithPartition(c *C) { +func (s *testIntegrationSuite9) TestCreateTableWithPartition(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test;") tk.MustExec("drop table if exists tp;") @@ -232,7 +232,7 @@ func (s *testIntegrationSuite) TestCreateTableWithPartition(c *C) { assertErrorCode(c, tk, `create table t33 (a int, b int) partition by hash(a) partitions 0;`, tmysql.ErrNoParts) } -func (s *testIntegrationSuite) TestCreateTableWithHashPartition(c *C) { +func (s *testIntegrationSuite7) TestCreateTableWithHashPartition(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test;") tk.MustExec("drop table if exists employees;") @@ -263,7 +263,7 @@ func (s *testIntegrationSuite) TestCreateTableWithHashPartition(c *C) { partition by hash( year(hired) ) partitions 4;`) } -func (s *testIntegrationSuite) TestCreateTableWithRangeColumnPartition(c *C) { +func (s *testIntegrationSuite10) TestCreateTableWithRangeColumnPartition(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test;") tk.MustExec("drop table if exists log_message_1;") @@ -363,7 +363,7 @@ create table log_message_1 ( "partition p1 values less than (2, maxvalue))") } -func (s *testIntegrationSuite) TestCreateTableWithKeyPartition(c *C) { +func (s *testIntegrationSuite8) TestCreateTableWithKeyPartition(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test;") tk.MustExec("drop table if exists tm1;") @@ -374,7 +374,7 @@ func (s *testIntegrationSuite) TestCreateTableWithKeyPartition(c *C) { partition by key(s1) partitions 10;`) } -func (s *testIntegrationSuite) TestAlterTableAddPartition(c *C) { +func (s *testIntegrationSuite5) TestAlterTableAddPartition(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test;") tk.MustExec("drop table if exists employees;") @@ -481,7 +481,7 @@ func (s *testIntegrationSuite) TestAlterTableAddPartition(c *C) { assertErrorCode(c, tk, sql7, tmysql.ErrSameNamePartition) } -func (s *testIntegrationSuite) TestAlterTableDropPartition(c *C) { +func (s *testIntegrationSuite6) TestAlterTableDropPartition(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("drop table if exists employees") @@ -618,7 +618,7 @@ func (s *testIntegrationSuite) TestAlterTableDropPartition(c *C) { assertErrorCode(c, tk, sql4, tmysql.ErrDropPartitionNonExistent) } -func (s *testIntegrationSuite) TestAddPartitionTooManyPartitions(c *C) { +func (s *testIntegrationSuite11) TestAddPartitionTooManyPartitions(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") count := ddl.PartitionCountLimit @@ -645,7 +645,7 @@ func (s *testIntegrationSuite) TestAddPartitionTooManyPartitions(c *C) { tk.MustExec(sql2) sql3 := `alter table p2 add partition ( - partition p1025 values less than (1025) + partition p1025 values less than (1025) );` assertErrorCode(c, tk, sql3, tmysql.ErrTooManyPartitions) } @@ -675,7 +675,7 @@ func checkPartitionDelRangeDone(c *C, s *testIntegrationSuite, partitionPrefix k return hasOldPartitionData } -func (s *testIntegrationSuite) TestTruncatePartitionAndDropTable(c *C) { +func (s *testIntegrationSuite6) TestTruncatePartitionAndDropTable(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test;") // Test truncate common table. @@ -736,7 +736,7 @@ func (s *testIntegrationSuite) TestTruncatePartitionAndDropTable(c *C) { oldPID := oldTblInfo.Meta().Partition.Definitions[0].ID tk.MustExec("truncate table t3;") partitionPrefix := tablecodec.EncodeTablePrefix(oldPID) - hasOldPartitionData := checkPartitionDelRangeDone(c, s, partitionPrefix) + hasOldPartitionData := checkPartitionDelRangeDone(c, s.testIntegrationSuite, partitionPrefix) c.Assert(hasOldPartitionData, IsFalse) // Test drop table partition. @@ -773,7 +773,7 @@ func (s *testIntegrationSuite) TestTruncatePartitionAndDropTable(c *C) { oldPID = oldTblInfo.Meta().Partition.Definitions[1].ID tk.MustExec("drop table t4;") partitionPrefix = tablecodec.EncodeTablePrefix(oldPID) - hasOldPartitionData = checkPartitionDelRangeDone(c, s, partitionPrefix) + hasOldPartitionData = checkPartitionDelRangeDone(c, s.testIntegrationSuite, partitionPrefix) c.Assert(hasOldPartitionData, IsFalse) assertErrorCode(c, tk, "select * from t4;", tmysql.ErrNoSuchTable) @@ -830,7 +830,7 @@ func (s *testIntegrationSuite) TestTruncatePartitionAndDropTable(c *C) { } } -func (s *testIntegrationSuite) TestPartitionUniqueKeyNeedAllFieldsInPf(c *C) { +func (s *testIntegrationSuite5) TestPartitionUniqueKeyNeedAllFieldsInPf(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test;") tk.MustExec("drop table if exists part1;") @@ -1033,7 +1033,7 @@ func (s *testIntegrationSuite) TestPartitionUniqueKeyNeedAllFieldsInPf(c *C) { assertErrorCode(c, tk, sql9, tmysql.ErrUniqueKeyNeedAllFieldsInPf) } -func (s *testIntegrationSuite) TestPartitionDropIndex(c *C) { +func (s *testIntegrationSuite3) TestPartitionDropIndex(c *C) { tk := testkit.NewTestKit(c, s.store) done := make(chan error, 1) tk.MustExec("use test_db") @@ -1113,7 +1113,7 @@ LOOP: tk.MustExec("drop table partition_drop_idx;") } -func (s *testIntegrationSuite) TestPartitionCancelAddIndex(c *C) { +func (s *testIntegrationSuite2) TestPartitionCancelAddIndex(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test_db") @@ -1251,7 +1251,7 @@ func backgroundExecOnJobUpdatedExported(c *C, store kv.Storage, ctx sessionctx.C return hook.OnJobUpdatedExported, c3IdxInfo, checkErr } -func (s *testIntegrationSuite) TestPartitionAddIndex(c *C) { +func (s *testIntegrationSuite1) TestPartitionAddIndex(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec(`create table partition_add_idx ( @@ -1305,7 +1305,7 @@ func testPartitionAddIndex(tk *testkit.TestKit, c *C) { tk.MustExec("drop table partition_add_idx") } -func (s *testIntegrationSuite) TestDropSchemaWithPartitionTable(c *C) { +func (s *testIntegrationSuite5) TestDropSchemaWithPartitionTable(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("drop database if exists test_db_with_partition") tk.MustExec("create database test_db_with_partition") @@ -1375,7 +1375,7 @@ func getPartitionTableRecordsNum(c *C, ctx sessionctx.Context, tbl table.Partiti return num } -func (s *testIntegrationSuite) TestPartitionErrorCode(c *C) { +func (s *testIntegrationSuite4) TestPartitionErrorCode(c *C) { tk := testkit.NewTestKit(c, s.store) // add partition tk.MustExec("set @@session.tidb_enable_table_partition = 1") diff --git a/ddl/db_test.go b/ddl/db_test.go index d7e00e1381491..c5867b6648576 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -58,9 +58,16 @@ const ( waitForCleanDataInterval = time.Millisecond * 100 ) -var _ = Suite(&testDBSuite{}) +var _ = Suite(&testDBSuite1{&testDBSuite{}}) +var _ = Suite(&testDBSuite2{&testDBSuite{}}) +var _ = Suite(&testDBSuite3{&testDBSuite{}}) +var _ = Suite(&testDBSuite4{&testDBSuite{}}) +var _ = Suite(&testDBSuite5{&testDBSuite{}}) +var _ = Suite(&testDBSuite6{&testDBSuite{}}) +var _ = Suite(&testDBSuite7{&testDBSuite{}}) +var _ = Suite(&testDBSuite8{&testDBSuite{}}) -const defaultBatchSize = 2048 +const defaultBatchSize = 1024 type testDBSuite struct { cluster *mocktikv.Cluster @@ -74,15 +81,15 @@ type testDBSuite struct { autoIDStep int64 } -func (s *testDBSuite) SetUpSuite(c *C) { +func setUpSuite(s *testDBSuite, c *C) { var err error - s.lease = 200 * time.Millisecond + s.lease = 100 * time.Millisecond session.SetSchemaLease(s.lease) session.SetStatsLease(0) s.schemaName = "test_db" s.autoIDStep = autoid.GetStep() - ddl.WaitTimeWhenErrorOccured = 1 * time.Microsecond + ddl.WaitTimeWhenErrorOccured = 0 s.cluster = mocktikv.NewCluster() mocktikv.BootstrapWithSingleStore(s.cluster) @@ -104,13 +111,30 @@ func (s *testDBSuite) SetUpSuite(c *C) { s.tk = testkit.NewTestKit(c, s.store) } -func (s *testDBSuite) TearDownSuite(c *C) { +func tearDownSuite(s *testDBSuite, c *C) { s.s.Execute(context.Background(), "drop database if exists test_db") s.s.Close() s.dom.Close() s.store.Close() } +func (s *testDBSuite) SetUpSuite(c *C) { + setUpSuite(s, c) +} + +func (s *testDBSuite) TearDownSuite(c *C) { + tearDownSuite(s, c) +} + +type testDBSuite1 struct{ *testDBSuite } +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 } + func assertErrorCode(c *C, tk *testkit.TestKit, sql string, errCode int) { _, err := tk.Exec(sql) c.Assert(err, NotNil) @@ -120,7 +144,7 @@ func assertErrorCode(c *C, tk *testkit.TestKit, sql string, errCode int) { c.Assert(tErr.ToSQLError().Code, DeepEquals, uint16(errCode), Commentf("MySQL code:%v", tErr.ToSQLError())) } -func (s *testDBSuite) TestAddIndexWithPK(c *C) { +func (s *testDBSuite6) TestAddIndexWithPK(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) @@ -143,7 +167,7 @@ func (s *testDBSuite) TestAddIndexWithPK(c *C) { s.tk.MustQuery("select * from test_add_index_with_pk2").Check(testkit.Rows("1 1 1 1", "2 2 2 2")) } -func (s *testDBSuite) TestRenameIndex(c *C) { +func (s *testDBSuite1) TestRenameIndex(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) s.tk.MustExec("create table t (pk int primary key, c int default 1, c1 int default 1, unique key k1(c), key k2(c1))") @@ -197,7 +221,7 @@ func backgroundExec(s kv.Storage, sql string, done chan error) { done <- errors.Trace(err) } -func (s *testDBSuite) TestAddUniqueIndexRollback(c *C) { +func (s *testDBSuite2) TestAddUniqueIndexRollback(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.mustExec(c, "use test_db") s.mustExec(c, "drop table if exists t1") @@ -256,7 +280,7 @@ LOOP: s.mustExec(c, "drop table t1") } -func (s *testDBSuite) TestCancelAddIndex(c *C) { +func (s *testDBSuite3) TestCancelAddIndex(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.mustExec(c, "use test_db") s.mustExec(c, "drop table if exists t1") @@ -322,7 +346,7 @@ LOOP: } // TestCancelAddIndex1 tests canceling ddl job when the add index worker is not started. -func (s *testDBSuite) TestCancelAddIndex1(c *C) { +func (s *testDBSuite4) TestCancelAddIndex1(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.mustExec(c, "use test_db") s.mustExec(c, "drop table if exists t") @@ -384,7 +408,7 @@ func (s *testDBSuite) TestCancelAddIndex1(c *C) { } // TestCancelDropIndex tests cancel ddl job which type is drop index. -func (s *testDBSuite) TestCancelDropIndex(c *C) { +func (s *testDBSuite5) TestCancelDropIndex(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.mustExec(c, "use test_db") s.mustExec(c, "drop table if exists t") @@ -470,7 +494,7 @@ func (s *testDBSuite) TestCancelDropIndex(c *C) { } // TestCancelTruncateTable tests cancel ddl job which type is truncate table. -func (s *testDBSuite) TestCancelTruncateTable(c *C) { +func (s *testDBSuite7) TestCancelTruncateTable(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.mustExec(c, "use test_db") s.mustExec(c, "create database if not exists test_truncate_table") @@ -516,7 +540,7 @@ func (s *testDBSuite) TestCancelTruncateTable(c *C) { } // TestCancelRenameIndex tests cancel ddl job which type is rename index. -func (s *testDBSuite) TestCancelRenameIndex(c *C) { +func (s *testDBSuite1) TestCancelRenameIndex(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.mustExec(c, "use test_db") s.mustExec(c, "create database if not exists test_rename_index") @@ -574,7 +598,7 @@ func (s *testDBSuite) TestCancelRenameIndex(c *C) { } // TestCancelDropTable tests cancel ddl job which type is drop table. -func (s *testDBSuite) TestCancelDropTableAndSchema(c *C) { +func (s *testDBSuite2) TestCancelDropTableAndSchema(c *C) { s.tk = testkit.NewTestKit(c, s.store) testCases := []struct { needAddTableOrDB bool @@ -661,7 +685,7 @@ func (s *testDBSuite) TestCancelDropTableAndSchema(c *C) { } } -func (s *testDBSuite) TestAddAnonymousIndex(c *C) { +func (s *testDBSuite3) TestAddAnonymousIndex(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) s.mustExec(c, "create table t_anonymous_index (c1 int, c2 int, C3 int)") @@ -711,14 +735,14 @@ func (s *testDBSuite) TestAddAnonymousIndex(c *C) { c.Assert(t.Indices()[1].Meta().Name.String(), Equals, "primary_3") } -func (s *testDBSuite) testAlterLock(c *C) { +func (s *testDBSuite4) testAlterLock(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) s.mustExec(c, "create table t_index_lock (c1 int, c2 int, C3 int)") s.mustExec(c, "alter table t_indx_lock add index (c1, c2), lock=none") } -func (s *testDBSuite) TestAddMultiColumnsIndex(c *C) { +func (s *testDBSuite5) TestAddMultiColumnsIndex(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) @@ -739,8 +763,11 @@ func (s *testDBSuite) TestAddMultiColumnsIndex(c *C) { s.tk.MustExec("admin check table test") } -func (s *testDBSuite) TestAddIndex(c *C) { +func (s *testDBSuite1) TestAddIndex1(c *C) { s.testAddIndex(c, false, "create table test_add_index (c1 bigint, c2 bigint, c3 bigint, primary key(c1))") +} + +func (s *testDBSuite2) TestAddIndex2(c *C) { s.testAddIndex(c, true, `create table test_add_index (c1 bigint, c2 bigint, c3 bigint, primary key(c1)) partition by range (c1) ( partition p0 values less than (3440), @@ -748,8 +775,14 @@ func (s *testDBSuite) TestAddIndex(c *C) { partition p2 values less than (122880), partition p3 values less than (204800), partition p4 values less than maxvalue)`) +} + +func (s *testDBSuite3) TestAddIndex3(c *C) { s.testAddIndex(c, true, `create table test_add_index (c1 bigint, c2 bigint, c3 bigint, primary key(c1)) partition by hash (c1) partitions 4;`) +} + +func (s *testDBSuite4) TestAddIndex4(c *C) { s.testAddIndex(c, true, `create table test_add_index (c1 bigint, c2 bigint, c3 bigint, primary key(c1)) partition by range columns (c1) ( partition p0 values less than (3440), @@ -776,6 +809,7 @@ func (s *testDBSuite) testAddIndex(c *C, testPartition bool, createTableSQL stri sql := fmt.Sprintf("insert into test_add_index values (%d, %d, %d)", i, i, i) s.mustExec(c, sql) } + // Add some discrete rows. maxBatch := 20 batchCnt := 100 @@ -919,7 +953,7 @@ LOOP: } // TestCancelAddTableAndDropTablePartition tests cancel ddl job which type is add/drop table partition. -func (s *testDBSuite) TestCancelAddTableAndDropTablePartition(c *C) { +func (s *testDBSuite1) TestCancelAddTableAndDropTablePartition(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.mustExec(c, "create database if not exists test_partition_table") s.mustExec(c, "use test_partition_table") @@ -1006,7 +1040,7 @@ func (s *testDBSuite) TestCancelAddTableAndDropTablePartition(c *C) { s.dom.DDL().(ddl.DDLForTest).SetHook(originalHook) } -func (s *testDBSuite) TestDropIndex(c *C) { +func (s *testDBSuite2) TestDropIndex(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) s.tk.MustExec("drop table if exists test_drop_index") @@ -1077,7 +1111,7 @@ LOOP: } // TestCancelDropColumn tests cancel ddl job which type is drop column. -func (s *testDBSuite) TestCancelDropColumn(c *C) { +func (s *testDBSuite3) TestCancelDropColumn(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) s.mustExec(c, "drop table if exists test_drop_column") @@ -1201,7 +1235,7 @@ func checkDelRangeDone(c *C, ctx sessionctx.Context, idx table.Index) { c.Assert(handles, HasLen, 0, Commentf("take time %v", time.Since(startTime))) } -func (s *testDBSuite) TestAddIndexWithDupCols(c *C) { +func (s *testDBSuite4) TestAddIndexWithDupCols(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) err1 := infoschema.ErrColumnExists.GenWithStackByArgs("b") @@ -1227,7 +1261,7 @@ func (s *testDBSuite) showColumns(c *C, tableName string) [][]interface{} { return s.mustQuery(c, fmt.Sprintf("show columns from %s", tableName)) } -func (s *testDBSuite) TestCreateIndexType(c *C) { +func (s *testDBSuite5) TestCreateIndexType(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) sql := `CREATE TABLE test_index ( @@ -1242,7 +1276,7 @@ func (s *testDBSuite) TestCreateIndexType(c *C) { s.tk.MustExec(sql) } -func (s *testDBSuite) TestColumn(c *C) { +func (s *testDBSuite8) TestColumn(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) s.tk.MustExec("create table t2 (c1 int, c2 int, c3 int)") @@ -1251,7 +1285,7 @@ func (s *testDBSuite) TestColumn(c *C) { s.tk.MustExec("drop table t2") } -func (s *testDBSuite) TestAddColumnTooMany(c *C) { +func (s *testDBSuite1) TestAddColumnTooMany(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") count := int(atomic.LoadUint32(&ddl.TableColumnCountLimit) - 1) @@ -1467,7 +1501,7 @@ LOOP: // TestDropColumn is for inserting value with a to-be-dropped column when do drop column. // Column info from schema in build-insert-plan should be public only, // otherwise they will not be consist with Table.Col(), then the server will panic. -func (s *testDBSuite) TestDropColumn(c *C) { +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") @@ -1494,7 +1528,7 @@ func (s *testDBSuite) TestDropColumn(c *C) { s.tk.MustExec("drop database drop_col_db") } -func (s *testDBSuite) TestPrimaryKey(c *C) { +func (s *testDBSuite3) TestPrimaryKey(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) @@ -1505,7 +1539,7 @@ func (s *testDBSuite) TestPrimaryKey(c *C) { c.Assert(ddl.ErrUnsupportedModifyPrimaryKey.Equal(err), IsTrue) } -func (s *testDBSuite) TestChangeColumn(c *C) { +func (s *testDBSuite4) TestChangeColumn(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) @@ -1599,7 +1633,7 @@ func match(c *C, row []interface{}, expected ...interface{}) { } } -func (s *testDBSuite) TestCreateTableWithLike(c *C) { +func (s *testDBSuite5) TestCreateTableWithLike(c *C) { s.tk = testkit.NewTestKit(c, s.store) // for the same database s.tk.MustExec("create database ctwl_db") @@ -1659,7 +1693,7 @@ func (s *testDBSuite) TestCreateTableWithLike(c *C) { } // TestCreateTableWithLike2 tests create table with like when refer table have non-public column/index. -func (s *testDBSuite) TestCreateTableWithLike2(c *C) { +func (s *testDBSuite6) TestCreateTableWithLike2(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test_db") s.tk.MustExec("drop table if exists t1,t2;") @@ -1669,6 +1703,7 @@ func (s *testDBSuite) TestCreateTableWithLike2(c *C) { tbl1 := testGetTableByName(c, s.s, "test_db", "t1") doneCh := make(chan error, 2) hook := &ddl.TestDDLCallback{} + var onceChecker sync.Map hook.OnJobRunBeforeExported = func(job *model.Job) { if job.Type != model.ActionAddColumn && job.Type != model.ActionDropColumn && job.Type != model.ActionAddIndex && job.Type != model.ActionDropIndex { return @@ -1676,7 +1711,13 @@ func (s *testDBSuite) TestCreateTableWithLike2(c *C) { if job.TableID != tbl1.Meta().ID { return } + if job.SchemaState == model.StateDeleteOnly { + if _, ok := onceChecker.Load(job.ID); ok { + return + } + + onceChecker.Store(job.ID, true) go backgroundExec(s.store, "create table t2 like t1", doneCh) } } @@ -1691,7 +1732,6 @@ func (s *testDBSuite) TestCreateTableWithLike2(c *C) { c.Assert(err, IsNil) s.tk.MustExec("alter table t2 add column e int") t2Info := testGetTableByName(c, s.s, "test_db", "t2") - c.Assert(len(t2Info.Meta().Columns), Equals, 4) c.Assert(len(t2Info.Meta().Columns), Equals, len(t2Info.Cols())) } checkTbl2() @@ -1709,10 +1749,11 @@ func (s *testDBSuite) TestCreateTableWithLike2(c *C) { c.Assert(err, IsNil) s.tk.MustExec("alter table t2 add column e int") tbl2 := testGetTableByName(c, s.s, "test_db", "t2") - c.Assert(len(tbl2.Meta().Columns), Equals, 4) c.Assert(len(tbl2.Meta().Columns), Equals, len(tbl2.Cols())) - c.Assert(len(tbl2.Meta().Indices), Equals, 1) - c.Assert(tbl2.Meta().Indices[0].Name.L, Equals, "idx1") + + for i := 0; i < len(tbl2.Meta().Indices); i++ { + c.Assert(tbl2.Meta().Indices[i].State, Equals, model.StatePublic) + } } checkTbl2() @@ -1723,7 +1764,7 @@ func (s *testDBSuite) TestCreateTableWithLike2(c *C) { } -func (s *testDBSuite) TestCreateTable(c *C) { +func (s *testDBSuite1) TestCreateTable(c *C) { s.tk.MustExec("use test") s.tk.MustExec("CREATE TABLE `t` (`a` double DEFAULT 1.0 DEFAULT now() DEFAULT 2.0 );") s.tk.MustExec("CREATE TABLE IF NOT EXISTS `t` (`a` double DEFAULT 1.0 DEFAULT now() DEFAULT 2.0 );") @@ -1763,7 +1804,7 @@ func (s *testDBSuite) TestCreateTable(c *C) { c.Assert(err.Error(), Equals, "[types:1291]Column 'a' has duplicated value 'B' in ENUM") } -func (s *testDBSuite) TestTableForeignKey(c *C) { +func (s *testDBSuite2) TestTableForeignKey(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("create table t1 (a int, b int);") @@ -1777,7 +1818,7 @@ func (s *testDBSuite) TestTableForeignKey(c *C) { s.tk.MustExec("drop table if exists t1,t2,t3;") } -func (s *testDBSuite) TestTruncateTable(c *C) { +func (s *testDBSuite3) TestTruncateTable(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("create table truncate_table (c1 int, c2 int)") @@ -1824,12 +1865,12 @@ func (s *testDBSuite) TestTruncateTable(c *C) { c.Assert(hasOldTableData, IsFalse) } -func (s *testDBSuite) TestRenameTable(c *C) { +func (s *testDBSuite4) TestRenameTable(c *C) { isAlterTable := false s.testRenameTable(c, "rename table %s to %s", isAlterTable) } -func (s *testDBSuite) TestAlterTableRenameTable(c *C) { +func (s *testDBSuite5) TestAlterTableRenameTable(c *C) { isAlterTable := true s.testRenameTable(c, "alter table %s rename to %s", isAlterTable) } @@ -1931,7 +1972,7 @@ func (s *testDBSuite) testRenameTable(c *C, sql string, isAlterTable bool) { s.tk.MustExec("drop database test1") } -func (s *testDBSuite) TestRenameMultiTables(c *C) { +func (s *testDBSuite1) TestRenameMultiTables(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("create table t1(id int)") @@ -1946,7 +1987,7 @@ func (s *testDBSuite) TestRenameMultiTables(c *C) { s.tk.MustExec("drop table t1, t2") } -func (s *testDBSuite) TestAddNotNullColumn(c *C) { +func (s *testDBSuite2) TestAddNotNullColumn(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test_db") // for different databases @@ -1972,7 +2013,7 @@ out: s.tk.MustExec("drop table tnn") } -func (s *testDBSuite) TestGeneratedColumnDDL(c *C) { +func (s *testDBSuite3) TestGeneratedColumnDDL(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") @@ -2047,7 +2088,7 @@ func (s *testDBSuite) TestGeneratedColumnDDL(c *C) { result.Check(testkit.Rows(`a int(11) YES `, `b bigint(20) YES VIRTUAL GENERATED`, `cnew bigint(20) YES `)) } -func (s *testDBSuite) TestComment(c *C) { +func (s *testDBSuite4) TestComment(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) s.tk.MustExec("drop table if exists ct, ct1") @@ -2077,7 +2118,7 @@ func (s *testDBSuite) TestComment(c *C) { s.tk.MustExec("drop table if exists ct, ct1") } -func (s *testDBSuite) TestRebaseAutoID(c *C) { +func (s *testDBSuite5) TestRebaseAutoID(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) @@ -2105,7 +2146,7 @@ func (s *testDBSuite) TestRebaseAutoID(c *C) { assertErrorCode(c, s.tk, "alter table tidb.test2 add column b int auto_increment key, auto_increment=10;", tmysql.ErrUnknown) } -func (s *testDBSuite) TestCheckColumnDefaultValue(c *C) { +func (s *testDBSuite7) TestCheckColumnDefaultValue(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test;") s.tk.MustExec("drop table if exists text_default_text;") @@ -2156,7 +2197,7 @@ func (s *testDBSuite) TestCheckColumnDefaultValue(c *C) { c.Assert(tblInfo.Meta().Columns[0].DefaultValue, Equals, `null`) } -func (s *testDBSuite) TestCharacterSetInColumns(c *C) { +func (s *testDBSuite1) TestCharacterSetInColumns(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("create database varchar_test;") defer s.tk.MustExec("drop database varchar_test;") @@ -2178,7 +2219,7 @@ func (s *testDBSuite) TestCharacterSetInColumns(c *C) { s.tk.MustExec("create table t15(id int) charset=utf8mb4;") } -func (s *testDBSuite) TestAddNotNullColumnWhileInsertOnDupUpdate(c *C) { +func (s *testDBSuite2) TestAddNotNullColumnWhileInsertOnDupUpdate(c *C) { tk1 := testkit.NewTestKit(c, s.store) tk1.MustExec("use " + s.schemaName) tk2 := testkit.NewTestKit(c, s.store) @@ -2209,7 +2250,7 @@ func (s *testDBSuite) TestAddNotNullColumnWhileInsertOnDupUpdate(c *C) { c.Assert(tk2Err, IsNil) } -func (s *testDBSuite) TestColumnModifyingDefinition(c *C) { +func (s *testDBSuite3) TestColumnModifyingDefinition(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("drop table if exists test2;") @@ -2234,7 +2275,7 @@ func (s *testDBSuite) TestColumnModifyingDefinition(c *C) { assertErrorCode(c, s.tk, "alter table test2 change c1 a1 bigint not null;", tmysql.WarnDataTruncated) } -func (s *testDBSuite) TestCheckTooBigFieldLength(c *C) { +func (s *testDBSuite4) TestCheckTooBigFieldLength(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("drop table if exists tr_01;") @@ -2260,7 +2301,7 @@ func (s *testDBSuite) TestCheckTooBigFieldLength(c *C) { s.tk.MustExec("alter table tr_05 modify column a varchar(16000) charset utf8mb4;") } -func (s *testDBSuite) TestCheckConvertToCharacter(c *C) { +func (s *testDBSuite5) TestCheckConvertToCharacter(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("drop table if exists t") @@ -2282,7 +2323,7 @@ func (s *testDBSuite) TestCheckConvertToCharacter(c *C) { c.Assert(t.Cols()[0].Charset, Equals, "binary") } -func (s *testDBSuite) TestModifyColumnRollBack(c *C) { +func (s *testDBSuite7) TestModifyColumnRollBack(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.mustExec(c, "use test_db") s.mustExec(c, "drop table if exists t1") @@ -2371,7 +2412,7 @@ LOOP: s.mustExec(c, "drop table t1") } -func (s *testDBSuite) TestModifyColumnNullToNotNull(c *C) { +func (s *testDBSuite1) TestModifyColumnNullToNotNull(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.mustExec(c, "use test_db") s.mustExec(c, "drop table if exists t1") @@ -2419,7 +2460,7 @@ func (s *testDBSuite) TestModifyColumnNullToNotNull(c *C) { s.mustExec(c, "drop table t1") } -func (s *testDBSuite) TestTransactionOnAddDropColumn(c *C) { +func (s *testDBSuite2) TestTransactionOnAddDropColumn(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.mustExec(c, "use test_db") s.mustExec(c, "drop table if exists t1") @@ -2474,7 +2515,7 @@ func (s *testDBSuite) TestTransactionOnAddDropColumn(c *C) { s.tk.MustQuery("select a,b from t1 order by a").Check(testkit.Rows("1 1", "1 1", "1 1", "2 2", "2 2", "2 2")) } -func (s *testDBSuite) TestTransactionWithWriteOnlyColumn(c *C) { +func (s *testDBSuite3) TestTransactionWithWriteOnlyColumn(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.mustExec(c, "use test_db") s.mustExec(c, "drop table if exists t1") @@ -2521,7 +2562,7 @@ func (s *testDBSuite) TestTransactionWithWriteOnlyColumn(c *C) { s.tk.MustQuery("select a from t1").Check(testkit.Rows("2")) } -func (s *testDBSuite) TestAddColumn2(c *C) { +func (s *testDBSuite4) TestAddColumn2(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.mustExec(c, "use test_db") s.mustExec(c, "drop table if exists t1") @@ -2591,7 +2632,7 @@ func (s *testDBSuite) TestAddColumn2(c *C) { s.tk.MustQuery("select a,b,_tidb_rowid from t2").Check(testkit.Rows("1 3 2")) } -func (s *testDBSuite) TestAddIndexForGeneratedColumn(c *C) { +func (s *testDBSuite5) TestAddIndexForGeneratedColumn(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test_db") s.tk.MustExec("create table t(y year NOT NULL DEFAULT '2155')") @@ -2629,7 +2670,7 @@ func (s *testDBSuite) TestAddIndexForGeneratedColumn(c *C) { s.tk.MustExec("admin check table gcai_table") } -func (s *testDBSuite) TestIssue9100(c *C) { +func (s *testDBSuite6) TestIssue9100(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test_db") tk.MustExec("create table employ (a int, b int) partition by range (b) (partition p0 values less than (1));") @@ -2644,7 +2685,7 @@ func (s *testDBSuite) TestIssue9100(c *C) { c.Assert(err.Error(), Equals, "[ddl:1503]A UNIQUE INDEX must include all columns in the table's partitioning function") } -func (s *testDBSuite) TestModifyColumnCharset(c *C) { +func (s *testDBSuite1) TestModifyColumnCharset(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test_db") s.tk.MustExec("create table t_mcc(a varchar(8) charset utf8, b varchar(8) charset utf8)") @@ -2672,7 +2713,7 @@ func (s *testDBSuite) TestModifyColumnCharset(c *C) { } -func (s *testDBSuite) TestAlterShardRowIDBits(c *C) { +func (s *testDBSuite2) TestAlterShardRowIDBits(c *C) { s.tk = testkit.NewTestKit(c, s.store) tk := s.tk