Skip to content

Commit 651e770

Browse files
authored
tests: update mysql-tester, enable table-lock in integrationtest (#48956)
close #45961
1 parent 37afb03 commit 651e770

38 files changed

+488
-391
lines changed

pkg/ddl/db_integration_test.go

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,8 +1817,6 @@ func TestParserIssue284(t *testing.T) {
18171817

18181818
func TestAddExpressionIndex(t *testing.T) {
18191819
config.UpdateGlobal(func(conf *config.Config) {
1820-
// Test for table lock.
1821-
conf.EnableTableLock = true
18221820
conf.Instance.SlowThreshold = 10000
18231821
conf.TiKVClient.AsyncCommit.SafeWindow = 0
18241822
conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0
@@ -1897,60 +1895,6 @@ func TestAddExpressionIndex(t *testing.T) {
18971895
})
18981896
}
18991897

1900-
func TestCreateExpressionIndexError(t *testing.T) {
1901-
config.UpdateGlobal(func(conf *config.Config) {
1902-
// Test for table lock.
1903-
conf.EnableTableLock = true
1904-
conf.Instance.SlowThreshold = 10000
1905-
conf.TiKVClient.AsyncCommit.SafeWindow = 0
1906-
conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0
1907-
conf.Experimental.AllowsExpressionIndex = true
1908-
})
1909-
store := testkit.CreateMockStore(t)
1910-
tk := testkit.NewTestKit(t, store)
1911-
tk.MustExec("use test")
1912-
tk.MustExec("drop table if exists t;")
1913-
tk.MustExec("create table t (a int, b real);")
1914-
tk.MustGetErrCode("alter table t add primary key ((a+b)) nonclustered;", errno.ErrFunctionalIndexPrimaryKey)
1915-
1916-
tk.MustGetErrCode("create table t(a int, index((cast(a as JSON))))", errno.ErrFunctionalIndexOnJSONOrGeometryFunction)
1917-
1918-
// Test for error
1919-
tk.MustExec("drop table if exists t;")
1920-
tk.MustExec("create table t (a int, b real);")
1921-
tk.MustGetErrCode("alter table t add primary key ((a+b)) nonclustered;", errno.ErrFunctionalIndexPrimaryKey)
1922-
tk.MustGetErrCode("alter table t add index ((rand()));", errno.ErrFunctionalIndexFunctionIsNotAllowed)
1923-
tk.MustGetErrCode("alter table t add index ((now()+1));", errno.ErrFunctionalIndexFunctionIsNotAllowed)
1924-
1925-
tk.MustExec("alter table t add column (_V$_idx_0 int);")
1926-
tk.MustGetErrCode("alter table t add index idx((a+1));", errno.ErrDupFieldName)
1927-
tk.MustExec("alter table t drop column _V$_idx_0;")
1928-
tk.MustExec("alter table t add index idx((a+1));")
1929-
tk.MustGetErrCode("alter table t add column (_V$_idx_0 int);", errno.ErrDupFieldName)
1930-
tk.MustExec("alter table t drop index idx;")
1931-
tk.MustExec("alter table t add column (_V$_idx_0 int);")
1932-
1933-
tk.MustExec("alter table t add column (_V$_expression_index_0 int);")
1934-
tk.MustGetErrCode("alter table t add index ((a+1));", errno.ErrDupFieldName)
1935-
tk.MustExec("alter table t drop column _V$_expression_index_0;")
1936-
tk.MustExec("alter table t add index ((a+1));")
1937-
tk.MustGetErrCode("alter table t drop column _V$_expression_index_0;", errno.ErrCantDropFieldOrKey)
1938-
tk.MustGetErrCode("alter table t add column e int as (_V$_expression_index_0 + 1);", errno.ErrBadField)
1939-
1940-
// NOTE (#18150): In creating expression index, row value is not allowed.
1941-
tk.MustExec("drop table if exists t;")
1942-
tk.MustGetErrCode("create table t (j json, key k (((j,j))))", errno.ErrFunctionalIndexRowValueIsNotAllowed)
1943-
tk.MustExec("create table t (j json, key k ((j+1),(j+1)))")
1944-
1945-
tk.MustGetErrCode("create table t1 (col1 int, index ((concat(''))));", errno.ErrWrongKeyColumnFunctionalIndex)
1946-
tk.MustGetErrCode("CREATE TABLE t1 (col1 INT, PRIMARY KEY ((ABS(col1))) NONCLUSTERED);", errno.ErrFunctionalIndexPrimaryKey)
1947-
1948-
// For issue 26349
1949-
tk.MustExec("drop table if exists t;")
1950-
tk.MustExec("create table t(id char(10) primary key, short_name char(10), name char(10), key n((upper(`name`))));")
1951-
tk.MustExec("update t t1 set t1.short_name='a' where t1.id='1';")
1952-
}
1953-
19541898
func queryIndexOnTable(dbName, tableName string) string {
19551899
return fmt.Sprintf("select distinct index_name, is_visible from information_schema.statistics where table_schema = '%s' and table_name = '%s' order by index_name", dbName, tableName)
19561900
}
@@ -2349,20 +2293,6 @@ func TestEnumAndSetDefaultValue(t *testing.T) {
23492293
require.Equal(t, "a", tbl.Meta().Columns[1].DefaultValue)
23502294
}
23512295

2352-
func TestStrictDoubleTypeCheck(t *testing.T) {
2353-
store := testkit.CreateMockStore(t)
2354-
tk := testkit.NewTestKit(t, store)
2355-
tk.MustExec("use test")
2356-
tk.MustExec("set @@tidb_enable_strict_double_type_check = 'ON'")
2357-
sql := "create table double_type_check(id int, c double(10));"
2358-
_, err := tk.Exec(sql)
2359-
require.Error(t, err)
2360-
require.Equal(t, "[parser:1149]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use", err.Error())
2361-
tk.MustExec("set @@tidb_enable_strict_double_type_check = 'OFF'")
2362-
defer tk.MustExec("set @@tidb_enable_strict_double_type_check = 'ON'")
2363-
tk.MustExec(sql)
2364-
}
2365-
23662296
func TestDuplicateErrorMessage(t *testing.T) {
23672297
defer collate.SetNewCollationEnabledForTest(true)
23682298
store := testkit.CreateMockStore(t)
@@ -2669,8 +2599,6 @@ func TestAvoidCreateViewOnLocalTemporaryTable(t *testing.T) {
26692599

26702600
func TestDropTemporaryTable(t *testing.T) {
26712601
config.UpdateGlobal(func(conf *config.Config) {
2672-
// Test for table lock.
2673-
conf.EnableTableLock = true
26742602
conf.Instance.SlowThreshold = 10000
26752603
conf.TiKVClient.AsyncCommit.SafeWindow = 0
26762604
conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0
@@ -2936,42 +2864,6 @@ func TestIssue29282(t *testing.T) {
29362864
}
29372865
}
29382866

2939-
// See https://github.com/pingcap/tidb/issues/35644
2940-
func TestCreateTempTableInTxn(t *testing.T) {
2941-
store := testkit.CreateMockStore(t)
2942-
tk := testkit.NewTestKit(t, store)
2943-
tk.MustExec("use test")
2944-
tk.MustExec("begin")
2945-
// new created temporary table should be visible
2946-
tk.MustExec("create temporary table t1(id int primary key, v int)")
2947-
tk.MustQuery("select * from t1").Check(testkit.Rows())
2948-
// new inserted data should be visible
2949-
tk.MustExec("insert into t1 values(123, 456)")
2950-
tk.MustQuery("select * from t1 where id=123").Check(testkit.Rows("123 456"))
2951-
// truncate table will clear data but table still visible
2952-
tk.MustExec("truncate table t1")
2953-
tk.MustQuery("select * from t1 where id=123").Check(testkit.Rows())
2954-
tk.MustExec("commit")
2955-
2956-
tk1 := testkit.NewTestKit(t, store)
2957-
tk1.MustExec("use test")
2958-
tk1.MustExec("create table tt(id int)")
2959-
tk1.MustExec("begin")
2960-
tk1.MustExec("create temporary table t1(id int)")
2961-
tk1.MustExec("insert into tt select * from t1")
2962-
tk1.MustExec("drop table tt")
2963-
2964-
tk2 := testkit.NewTestKit(t, store)
2965-
tk2.MustExec("use test")
2966-
tk2.MustExec("create table t2(id int primary key, v int)")
2967-
tk2.MustExec("insert into t2 values(234, 567)")
2968-
tk2.MustExec("begin")
2969-
// create a new temporary table with the same name will override physical table
2970-
tk2.MustExec("create temporary table t2(id int primary key, v int)")
2971-
tk2.MustQuery("select * from t2 where id=234").Check(testkit.Rows())
2972-
tk2.MustExec("commit")
2973-
}
2974-
29752867
// See https://github.com/pingcap/tidb/issues/29327
29762868
func TestEnumDefaultValue(t *testing.T) {
29772869
store := testkit.CreateMockStore(t, mockstore.WithDDLChecker())

pkg/ddl/tests/partition/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ go_test(
88
"main_test.go",
99
],
1010
flaky = True,
11-
shard_count = 48,
11+
shard_count = 47,
1212
deps = [
1313
"//pkg/config",
1414
"//pkg/ddl",

pkg/ddl/tests/partition/db_partition_test.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,49 +2454,6 @@ func TestExchangePartitionAutoID(t *testing.T) {
24542454
tk.MustQuery("select count(*) from pt where a >= 4000000").Check(testkit.Rows("1"))
24552455
}
24562456

2457-
func TestExchangePartitionExpressIndex(t *testing.T) {
2458-
restore := config.RestoreFunc()
2459-
defer restore()
2460-
config.UpdateGlobal(func(conf *config.Config) {
2461-
// Test for table lock.
2462-
conf.EnableTableLock = true
2463-
conf.Instance.SlowThreshold = 10000
2464-
conf.TiKVClient.AsyncCommit.SafeWindow = 0
2465-
conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0
2466-
conf.Experimental.AllowsExpressionIndex = true
2467-
})
2468-
store := testkit.CreateMockStore(t)
2469-
tk := testkit.NewTestKit(t, store)
2470-
tk.MustExec("use test")
2471-
tk.MustExec("set @@tidb_enable_exchange_partition=1")
2472-
defer tk.MustExec("set @@tidb_enable_exchange_partition=0")
2473-
tk.MustExec("drop table if exists pt1;")
2474-
tk.MustExec("create table pt1(a int, b int, c int) PARTITION BY hash (a) partitions 1;")
2475-
tk.MustExec("alter table pt1 add index idx((a+c));")
2476-
2477-
tk.MustExec("drop table if exists nt1;")
2478-
tk.MustExec("create table nt1(a int, b int, c int);")
2479-
tk.MustGetErrCode("alter table pt1 exchange partition p0 with table nt1;", errno.ErrTablesDifferentMetadata)
2480-
2481-
tk.MustExec("alter table nt1 add column (`_V$_idx_0` bigint(20) generated always as (a+b) virtual);")
2482-
tk.MustGetErrCode("alter table pt1 exchange partition p0 with table nt1;", errno.ErrTablesDifferentMetadata)
2483-
2484-
// test different expression index when expression returns same field type
2485-
tk.MustExec("alter table nt1 drop column `_V$_idx_0`;")
2486-
tk.MustExec("alter table nt1 add index idx((b-c));")
2487-
tk.MustGetErrCode("alter table pt1 exchange partition p0 with table nt1;", errno.ErrTablesDifferentMetadata)
2488-
2489-
// test different expression index when expression returns different field type
2490-
tk.MustExec("alter table nt1 drop index idx;")
2491-
tk.MustExec("alter table nt1 add index idx((concat(a, b)));")
2492-
tk.MustGetErrCode("alter table pt1 exchange partition p0 with table nt1;", errno.ErrTablesDifferentMetadata)
2493-
2494-
tk.MustExec("drop table if exists nt2;")
2495-
tk.MustExec("create table nt2 (a int, b int, c int)")
2496-
tk.MustExec("alter table nt2 add index idx((a+c))")
2497-
tk.MustExec("alter table pt1 exchange partition p0 with table nt2")
2498-
}
2499-
25002457
func TestAddPartitionTooManyPartitions(t *testing.T) {
25012458
store := testkit.CreateMockStore(t)
25022459
tk := testkit.NewTestKit(t, store)
@@ -3036,14 +2993,6 @@ func TestPartitionErrorCode(t *testing.T) {
30362993
}
30372994

30382995
func TestCommitWhenSchemaChange(t *testing.T) {
3039-
restore := config.RestoreFunc()
3040-
defer restore()
3041-
config.UpdateGlobal(func(conf *config.Config) {
3042-
// Test for table lock.
3043-
conf.EnableTableLock = true
3044-
conf.Instance.SlowThreshold = 10000
3045-
conf.Experimental.AllowsExpressionIndex = true
3046-
})
30472996
store := testkit.CreateMockStoreWithSchemaLease(t, time.Second)
30482997
tk := testkit.NewTestKit(t, store)
30492998
tk.MustExec("set global tidb_enable_metadata_lock=0")

pkg/ddl/tests/serial/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ go_test(
88
"serial_test.go",
99
],
1010
flaky = True,
11-
shard_count = 20,
11+
shard_count = 19,
1212
deps = [
1313
"//pkg/config",
1414
"//pkg/ddl",

pkg/ddl/tests/serial/serial_test.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -846,13 +846,13 @@ func TestCanceledJobTakeTime(t *testing.T) {
846846
require.Less(t, sub, ddl.GetWaitTimeWhenErrorOccurred())
847847
}
848848

849-
func TestTableLocksEnable(t *testing.T) {
849+
func TestTableLocksDisable(t *testing.T) {
850850
store := testkit.CreateMockStore(t)
851851
tk := testkit.NewTestKit(t, store)
852852
tk.MustExec("use test")
853853
tk.MustExec("create table t1 (a int)")
854854

855-
// Test for enable table lock config.
855+
// Test for disable table lock config.
856856
defer config.RestoreFunc()()
857857
config.UpdateGlobal(func(conf *config.Config) {
858858
conf.EnableTableLock = false
@@ -1285,20 +1285,3 @@ func TestGetReverseKey(t *testing.T) {
12851285
endKey = maxKey.Next()
12861286
checkRet(startKey, endKey, endKey)
12871287
}
1288-
1289-
func TestLocalTemporaryTableBlockedDDL(t *testing.T) {
1290-
store := testkit.CreateMockStore(t)
1291-
tk := testkit.NewTestKit(t, store)
1292-
tk.MustExec("use test")
1293-
tk.MustExec("create table t1 (id int)")
1294-
tk.MustExec("create temporary table tmp1 (id int primary key, a int unique, b int)")
1295-
require.ErrorIs(t, tk.ExecToErr("rename table tmp1 to tmp2"), dbterror.ErrUnsupportedLocalTempTableDDL)
1296-
require.ErrorIs(t, tk.ExecToErr("alter table tmp1 add column c int"), dbterror.ErrUnsupportedLocalTempTableDDL)
1297-
require.ErrorIs(t, tk.ExecToErr("alter table tmp1 add index b(b)"), dbterror.ErrUnsupportedLocalTempTableDDL)
1298-
require.ErrorIs(t, tk.ExecToErr("create index a on tmp1(b)"), dbterror.ErrUnsupportedLocalTempTableDDL)
1299-
require.ErrorIs(t, tk.ExecToErr("drop index a on tmp1"), dbterror.ErrUnsupportedLocalTempTableDDL)
1300-
require.ErrorIs(t, tk.ExecToErr("lock tables tmp1 read"), dbterror.ErrUnsupportedLocalTempTableDDL)
1301-
require.ErrorIs(t, tk.ExecToErr("lock tables tmp1 write"), dbterror.ErrUnsupportedLocalTempTableDDL)
1302-
require.ErrorIs(t, tk.ExecToErr("lock tables t1 read, tmp1 read"), dbterror.ErrUnsupportedLocalTempTableDDL)
1303-
require.ErrorIs(t, tk.ExecToErr("admin cleanup table lock tmp1"), dbterror.ErrUnsupportedLocalTempTableDDL)
1304-
}

pkg/executor/test/executor/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ go_test(
88
"main_test.go",
99
],
1010
flaky = True,
11-
shard_count = 46,
11+
shard_count = 45,
1212
deps = [
1313
"//pkg/config",
1414
"//pkg/ddl",
@@ -21,7 +21,6 @@ go_test(
2121
"//pkg/meta",
2222
"//pkg/meta/autoid",
2323
"//pkg/parser",
24-
"//pkg/parser/auth",
2524
"//pkg/parser/model",
2625
"//pkg/parser/mysql",
2726
"//pkg/parser/terror",

pkg/executor/test/executor/executor_test.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
"github.com/pingcap/tidb/pkg/meta"
4242
"github.com/pingcap/tidb/pkg/meta/autoid"
4343
"github.com/pingcap/tidb/pkg/parser"
44-
"github.com/pingcap/tidb/pkg/parser/auth"
4544
"github.com/pingcap/tidb/pkg/parser/model"
4645
"github.com/pingcap/tidb/pkg/parser/mysql"
4746
"github.com/pingcap/tidb/pkg/parser/terror"
@@ -2576,33 +2575,6 @@ func TestIsFastPlan(t *testing.T) {
25762575
}
25772576
}
25782577

2579-
func TestTableLockPrivilege(t *testing.T) {
2580-
store := testkit.CreateMockStore(t)
2581-
tk := testkit.NewTestKit(t, store)
2582-
tk2 := testkit.NewTestKit(t, store)
2583-
tk.MustExec("use test")
2584-
tk.MustExec("create table t(a int)")
2585-
tk.MustExec("create user 'testuser'@'localhost'")
2586-
require.NoError(t, tk2.Session().Auth(&auth.UserIdentity{Username: "testuser", Hostname: "localhost"}, nil, nil, nil))
2587-
tk2.MustGetErrMsg("LOCK TABLE test.t WRITE", "[planner:1044]Access denied for user 'testuser'@'localhost' to database 'test'")
2588-
tk.MustExec("GRANT LOCK TABLES ON test.* to 'testuser'@'localhost'")
2589-
tk2.MustGetErrMsg("LOCK TABLE test.t WRITE", "[planner:1142]SELECT command denied to user 'testuser'@'localhost' for table 't'")
2590-
tk.MustExec("REVOKE ALL ON test.* FROM 'testuser'@'localhost'")
2591-
tk.MustExec("GRANT SELECT ON test.* to 'testuser'@'localhost'")
2592-
tk2.MustGetErrMsg("LOCK TABLE test.t WRITE", "[planner:1044]Access denied for user 'testuser'@'localhost' to database 'test'")
2593-
tk.MustExec("GRANT LOCK TABLES ON test.* to 'testuser'@'localhost'")
2594-
tk2.MustExec("LOCK TABLE test.t WRITE")
2595-
2596-
tk.MustExec("create database test2")
2597-
tk.MustExec("create table test2.t2(a int)")
2598-
tk2.MustGetErrMsg("LOCK TABLE test.t WRITE, test2.t2 WRITE", "[planner:1044]Access denied for user 'testuser'@'localhost' to database 'test2'")
2599-
tk.MustExec("GRANT LOCK TABLES ON test2.* to 'testuser'@'localhost'")
2600-
tk2.MustGetErrMsg("LOCK TABLE test.t WRITE, test2.t2 WRITE", "[planner:1142]SELECT command denied to user 'testuser'@'localhost' for table 't2'")
2601-
tk.MustExec("GRANT SELECT ON test2.* to 'testuser'@'localhost'")
2602-
tk2.MustExec("LOCK TABLE test.t WRITE, test2.t2 WRITE")
2603-
tk.MustExec("LOCK TABLE test.t WRITE, test2.t2 WRITE")
2604-
}
2605-
26062578
func TestGlobalMemoryControl2(t *testing.T) {
26072579
store, dom := testkit.CreateMockStoreAndDomain(t)
26082580

pkg/executor/test/fktest/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ go_test(
88
"main_test.go",
99
],
1010
flaky = True,
11-
shard_count = 25,
11+
shard_count = 24,
1212
deps = [
1313
"//pkg/config",
1414
"//pkg/executor",
15-
"//pkg/infoschema",
1615
"//pkg/kv",
1716
"//pkg/meta/autoid",
1817
"//pkg/parser",

pkg/executor/test/fktest/foreign_key_test.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ import (
2424
"testing"
2525
"time"
2626

27-
"github.com/pingcap/tidb/pkg/config"
2827
"github.com/pingcap/tidb/pkg/executor"
29-
"github.com/pingcap/tidb/pkg/infoschema"
3028
"github.com/pingcap/tidb/pkg/kv"
3129
"github.com/pingcap/tidb/pkg/parser"
3230
"github.com/pingcap/tidb/pkg/parser/ast"
@@ -2339,36 +2337,6 @@ func TestPrivilegeCheckInForeignKeyCascade(t *testing.T) {
23392337
}
23402338
}
23412339

2342-
func TestTableLockInForeignKeyCascade(t *testing.T) {
2343-
store := testkit.CreateMockStore(t)
2344-
tk := testkit.NewTestKit(t, store)
2345-
tk.MustExec("set @@global.tidb_enable_foreign_key=1")
2346-
tk.MustExec("set @@foreign_key_checks=1")
2347-
tk.MustExec("use test")
2348-
tk2 := testkit.NewTestKit(t, store)
2349-
tk2.MustExec("use test")
2350-
tk2.MustExec("set @@foreign_key_checks=1")
2351-
// enable table lock
2352-
config.UpdateGlobal(func(conf *config.Config) {
2353-
conf.EnableTableLock = true
2354-
})
2355-
defer func() {
2356-
config.UpdateGlobal(func(conf *config.Config) {
2357-
conf.EnableTableLock = false
2358-
})
2359-
}()
2360-
tk.MustExec("create table t1 (id int key);")
2361-
tk.MustExec("create table t2 (id int key, foreign key fk (id) references t1(id) ON DELETE CASCADE ON UPDATE CASCADE);")
2362-
tk.MustExec("insert into t1 values (1), (2), (3);")
2363-
tk.MustExec("insert into t2 values (1), (2), (3);")
2364-
tk.MustExec("lock table t2 read;")
2365-
tk2.MustGetDBError("delete from t1 where id = 1", infoschema.ErrTableLocked)
2366-
tk.MustExec("unlock tables;")
2367-
tk2.MustExec("delete from t1 where id = 1")
2368-
tk.MustQuery("select * from t1 order by id").Check(testkit.Rows("2", "3"))
2369-
tk.MustQuery("select * from t2 order by id").Check(testkit.Rows("2", "3"))
2370-
}
2371-
23722340
func TestForeignKeyIssue39732(t *testing.T) {
23732341
store := testkit.CreateMockStore(t)
23742342
tk := testkit.NewTestKit(t, store)

0 commit comments

Comments
 (0)