Skip to content

Commit

Permalink
tests, ddl: move IT tests in ddl/ to tests/integrationtest (PART …
Browse files Browse the repository at this point in the history
…4) (#47591)

close #47429
  • Loading branch information
Defined2014 authored Oct 13, 2023
1 parent 069db60 commit e58b008
Show file tree
Hide file tree
Showing 18 changed files with 5,866 additions and 3,431 deletions.
2 changes: 1 addition & 1 deletion ddl/tests/partition/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_test(
"main_test.go",
],
flaky = True,
shard_count = 50,
shard_count = 47,
deps = [
"//config",
"//ddl",
Expand Down
3,344 changes: 60 additions & 3,284 deletions ddl/tests/partition/db_partition_test.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ddl/tests/resourcegroup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ go_test(
srcs = ["resource_group_test.go"],
flaky = True,
race = "on",
shard_count = 6,
shard_count = 5,
deps = [
"//ddl/resourcegroup",
"//ddl/util/callback",
Expand Down
21 changes: 0 additions & 21 deletions ddl/tests/resourcegroup/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,27 +311,6 @@ func TestResourceGroupRunaway(t *testing.T) {
tk.MustGetErrCode("select /*+ resource_group(rg3) */ * from t", mysql.ErrResourceGroupQueryRunawayQuarantine)
}

func TestResourceGroupHint(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)

tk.MustExec("use test")
tk.MustExec("create table t1(c1 int)")
tk.MustExec("insert into t1 values(1)")

tk.MustExec("set global tidb_enable_resource_control='on'")
tk.MustExec("create resource group rg1 ru_per_sec=1000")
tk.MustQuery("select /*+ resource_group(default) */ * from t1")
tk.MustQuery("select /*+ resource_group(rg1) */ * from t1")
tk.MustQuery("select /*+ resource_group(rg1) resource_group(default) */ * from t1")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 RESOURCE_GROUP() is defined more than once, only the last definition takes effect: RESOURCE_GROUP(default)"))
tk.MustQuery("select /*+ resource_group(rg1) */ DB, RESOURCE_GROUP from information_schema.processlist").Check(testkit.Rows("test rg1"))
tk.MustQuery("select DB, RESOURCE_GROUP from information_schema.processlist").Check(testkit.Rows("test default"))
tk.MustExec("set global tidb_enable_resource_control='off'")
tk.MustQuery("select /*+ resource_group(rg1) */ DB, RESOURCE_GROUP from information_schema.processlist").Check(testkit.Rows("test default"))
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 8250 Resource control feature is disabled. Run `SET GLOBAL tidb_enable_resource_control='on'` to enable the feature"))
}

func TestAlreadyExistsDefaultResourceGroup(t *testing.T) {
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/domain/infosync/managerAlreadyCreateSomeGroups", `return(true)`))
defer func() {
Expand Down
2 changes: 1 addition & 1 deletion ddl/tests/serial/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_test(
"serial_test.go",
],
flaky = True,
shard_count = 24,
shard_count = 20,
deps = [
"//config",
"//ddl",
Expand Down
81 changes: 0 additions & 81 deletions ddl/tests/serial/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ func GetMaxRowID(store kv.Storage, priority int, t table.Table, startHandle, end
return ddl.GetRangeEndKey(ddl.NewJobContext(), store, priority, t.RecordPrefix(), startHandle, endHandle)
}

func TestTruncateAllPartitions(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table partition_table (v int) partition by hash (v) partitions 10")
tk.MustExec("insert into partition_table values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10)")
tk.MustExec("alter table partition_table truncate partition all")
tk.MustQuery("select count(*) from partition_table").Check(testkit.Rows("0"))
}

func TestIssue23872(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down Expand Up @@ -872,17 +862,6 @@ func TestTableLocksEnable(t *testing.T) {
tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1235 UNLOCK TABLES is not supported. To enable this experimental feature, set 'enable-table-lock' in the configuration file."))
}

func TestAutoRandomOnTemporaryTable(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists auto_random_temporary")
err := tk.ExecToErr("create global temporary table auto_random_temporary (a bigint primary key auto_random(3), b varchar(255)) on commit delete rows")
require.Equal(t, core.ErrOptOnTemporaryTable.GenWithStackByArgs("auto_random").Error(), err.Error())
err = tk.ExecToErr("create temporary table t(a bigint key auto_random)")
require.Equal(t, core.ErrOptOnTemporaryTable.GenWithStackByArgs("auto_random").Error(), err.Error())
}

func TestAutoRandom(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down Expand Up @@ -1121,32 +1100,6 @@ func TestAutoRandom(t *testing.T) {
})
}

func TestAutoRandomWithRangeBits(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
// Test normal usages.
tk.MustExec("create table t (a bigint auto_random(5, 64) primary key, b int);")
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (a bigint unsigned auto_random(5, 32) primary key, b int);")

// Test create auto_random table with invalid range bits.
expectErr := dbterror.ErrInvalidAutoRandom
tk.MustExec("drop table if exists t;")
err := tk.ExecToErr("create table t (a bigint auto_random(5, 31) primary key, b int);")
require.EqualError(t, err, expectErr.FastGenByArgs(fmt.Sprintf(autoid.AutoRandomInvalidRangeBits, 32, 64, 31)).Error())
err = tk.ExecToErr("create table t (a bigint auto_random(5, 65) primary key, b int);")
require.EqualError(t, err, expectErr.FastGenByArgs(fmt.Sprintf(autoid.AutoRandomInvalidRangeBits, 32, 64, 65)).Error())
err = tk.ExecToErr("create table t (a bigint auto_random(15, 32) primary key, b int);")
require.EqualError(t, err, expectErr.FastGenByArgs(autoid.AutoRandomIncrementalBitsTooSmall).Error())

// Alter table range bits is not supported.
tk.MustExec("create table t (a bigint auto_random(5, 64) primary key, b int);")
err = tk.ExecToErr("alter table t modify column a bigint auto_random(5, 32);")
require.EqualError(t, err, expectErr.FastGenByArgs(autoid.AutoRandomUnsupportedAlterRangeBits).Error())
tk.MustExec("alter table t modify column a bigint auto_random(15, 64);")
}

func TestAutoRandomWithPreSplitRegion(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down Expand Up @@ -1184,40 +1137,6 @@ func TestAutoRandomWithPreSplitRegion(t *testing.T) {
require.Equal(t, fmt.Sprintf("t_%d_r_3221225472", tbl.Meta().ID), rows[3][1])
}

func TestModifyingColumn4NewCollations(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("create database dct")
tk.MustExec("use dct")
tk.MustExec("create table t(b varchar(10) collate utf8_bin, c varchar(10) collate utf8_general_ci) collate utf8_bin")
// Column collation can be changed as long as there is no index defined.
tk.MustExec("alter table t modify b varchar(10) collate utf8_general_ci")
tk.MustExec("alter table t modify c varchar(10) collate utf8_bin")
tk.MustExec("alter table t modify c varchar(10) collate utf8_unicode_ci")
tk.MustExec("alter table t charset utf8 collate utf8_general_ci")
tk.MustExec("alter table t convert to charset utf8 collate utf8_bin")
tk.MustExec("alter table t convert to charset utf8 collate utf8_unicode_ci")
tk.MustExec("alter table t convert to charset utf8 collate utf8_general_ci")
tk.MustExec("alter table t modify b varchar(10) collate utf8_unicode_ci")
tk.MustExec("alter table t modify b varchar(10) collate utf8_bin")

tk.MustExec("alter table t add index b_idx(b)")
tk.MustExec("alter table t add index c_idx(c)")
tk.MustGetErrMsg("alter table t modify b varchar(10) collate utf8_general_ci", "[ddl:8200]Unsupported modifying collation of column 'b' from 'utf8_bin' to 'utf8_general_ci' when index is defined on it.")
tk.MustGetErrMsg("alter table t modify c varchar(10) collate utf8_bin", "[ddl:8200]Unsupported modifying collation of column 'c' from 'utf8_general_ci' to 'utf8_bin' when index is defined on it.")
tk.MustGetErrMsg("alter table t modify c varchar(10) collate utf8_unicode_ci", "[ddl:8200]Unsupported modifying collation of column 'c' from 'utf8_general_ci' to 'utf8_unicode_ci' when index is defined on it.")
tk.MustGetErrMsg("alter table t convert to charset utf8 collate utf8_general_ci", "[ddl:8200]Unsupported converting collation of column 'b' from 'utf8_bin' to 'utf8_general_ci' when index is defined on it.")
// Change to a compatible collation is allowed.
tk.MustExec("alter table t modify c varchar(10) collate utf8mb4_general_ci")
// Change the default collation of table is allowed.
tk.MustExec("alter table t collate utf8mb4_general_ci")
tk.MustExec("alter table t charset utf8mb4 collate utf8mb4_bin")
tk.MustExec("alter table t charset utf8mb4 collate utf8mb4_unicode_ci")
tk.MustExec("alter table t charset utf8mb4 collate utf8mb4_zh_pinyin_tidb_as_cs")
// Change the default collation of database is allowed.
tk.MustExec("alter database dct charset utf8mb4 collate utf8mb4_general_ci")
}

func TestForbidUnsupportedCollations(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
2 changes: 1 addition & 1 deletion ddl/tests/tiflash/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_test(
"main_test.go",
],
flaky = True,
shard_count = 34,
shard_count = 32,
deps = [
"//config",
"//ddl",
Expand Down
37 changes: 0 additions & 37 deletions ddl/tests/tiflash/ddl_tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,16 +766,6 @@ func TestTiFlashBackoff(t *testing.T) {
require.True(t, tb.Meta().TiFlashReplica.Available)
}

func TestAlterDatabaseErrorGrammar(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustGetErrMsg("ALTER DATABASE t SET TIFLASH REPLICA 1 SET TIFLASH REPLICA 2 LOCATION LABELS 'a','b'", "[ddl:8200]Unsupported multi schema change for set tiflash replica")
tk.MustGetErrMsg("ALTER DATABASE t SET TIFLASH REPLICA 1 SET TIFLASH REPLICA 2", "[ddl:8200]Unsupported multi schema change for set tiflash replica")
tk.MustGetErrMsg("ALTER DATABASE t SET TIFLASH REPLICA 1 LOCATION LABELS 'a','b' SET TIFLASH REPLICA 2", "[ddl:8200]Unsupported multi schema change for set tiflash replica")
tk.MustGetErrMsg("ALTER DATABASE t SET TIFLASH REPLICA 1 LOCATION LABELS 'a','b' SET TIFLASH REPLICA 2 LOCATION LABELS 'a','b'", "[ddl:8200]Unsupported multi schema change for set tiflash replica")
}

func TestAlterDatabaseBasic(t *testing.T) {
s, teardown := createTiFlashContext(t)
defer teardown()
Expand Down Expand Up @@ -812,33 +802,6 @@ func TestAlterDatabaseBasic(t *testing.T) {
tk.MustGetErrMsg("alter database tiflash_ddl set tiflash replica 3", "the tiflash replica count: 3 should be less than the total tiflash server count: 2")
}

func checkBatchPandingNum(t *testing.T, tkx *testkit.TestKit, level string, value string, ok bool) {
l := len(tkx.MustQuery(fmt.Sprintf("show %v variables where Variable_name='tidb_batch_pending_tiflash_count' and Value='%v'", level, value)).Rows())
if ok {
require.Equal(t, 1, l)
} else {
require.Equal(t, 0, l)
}
}

func TestTiFlashBatchAddVariables(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("set SESSION tidb_batch_pending_tiflash_count=5")
tk.MustExec("set GLOBAL tidb_batch_pending_tiflash_count=6")

checkBatchPandingNum(t, tk, "session", "5", true)
checkBatchPandingNum(t, tk, "global", "6", true)
checkBatchPandingNum(t, tk, "global", "1.5", false)

tk.MustGetErrMsg("set GLOBAL tidb_batch_pending_tiflash_count=1.5", "[variable:1232]Incorrect argument type to variable 'tidb_batch_pending_tiflash_count'")
checkBatchPandingNum(t, tk, "global", "6", true)

tk2 := testkit.NewTestKit(t, store)
checkBatchPandingNum(t, tk2, "session", "6", true)
}

func execWithTimeout(t *testing.T, tk *testkit.TestKit, to time.Duration, sql string) (bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), to)
defer cancel()
Expand Down
Loading

0 comments on commit e58b008

Please sign in to comment.