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

tests: move IT in executor to tests/integrationtest (PART 9) #48179

Merged
merged 9 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions pkg/executor/stale_txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1315,23 +1315,6 @@ func TestPlanCacheWithStaleReadByBinaryProto(t *testing.T) {
tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 10"))
}

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

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_txn_mode='pessimistic'")
tk.MustExec("set tx_isolation = 'READ-COMMITTED'")
tk.MustExec("create table t1 (id int primary key, v int)")
tk.MustExec("insert into t1 values(1, 10)")
time.Sleep(time.Millisecond * 100)
tk.MustExec("set @a=now(6)")
time.Sleep(time.Millisecond * 100)
tk.MustExec("update t1 set v=100 where id=1")
tk.MustExec("set autocommit=0")
tk.MustQuery("select * from t1 as of timestamp @a").Check(testkit.Rows("1 10"))
}

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

Expand All @@ -1347,33 +1330,6 @@ func TestIssue33728(t *testing.T) {
require.Equal(t, "[planner:8135]invalid as of timestamp: as of timestamp cannot be NULL", err.Error())
}

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

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t1 (id int primary key, v int)")
tk.MustExec("insert into t1 values(1, 10)")
time.Sleep(time.Millisecond * 100)
tk.MustExec("set @a=now(6)")
time.Sleep(time.Millisecond * 100)
tk.MustExec("update t1 set v=100 where id=1")

tk.MustQuery("select * from t1 as of timestamp @a where v=(select v from t1 as of timestamp @a where id=1)").
Check(testkit.Rows("1 10"))

tk.MustQuery("select (select v from t1 as of timestamp @a where id=1) as v").
Check(testkit.Rows("10"))
}

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

tk := testkit.NewTestKit(t, store)
// This query should not panic
tk.MustQuery("select * from information_schema.ddl_jobs as of timestamp now()")
}

func TestStalePrepare(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/test/admintest/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 = 21,
shard_count = 18,
deps = [
"//pkg/config",
"//pkg/domain",
Expand Down
60 changes: 0 additions & 60 deletions pkg/executor/test/admintest/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,53 +45,6 @@ import (
"go.uber.org/zap"
)

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

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`drop table if exists check_index_test;`)
tk.MustExec(`create table check_index_test (a int, b varchar(10), index a_b (a, b), index b (b))`)
tk.MustExec(`insert check_index_test values (3, "ab"),(2, "cd"),(1, "ef"),(-1, "hi")`)
result := tk.MustQuery("admin check index check_index_test a_b (2, 4);")
result.Check(testkit.Rows("1 ef 3", "2 cd 2"))

result = tk.MustQuery("admin check index check_index_test a_b (3, 5);")
result.Check(testkit.Rows("-1 hi 4", "1 ef 3"))

tk.MustExec("use mysql")
result = tk.MustQuery("admin check index test.check_index_test a_b (2, 3), (4, 5);")
result.Check(testkit.Rows("-1 hi 4", "2 cd 2"))
}

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

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
check := func() {
tk.MustExec("insert admin_test (c1, c2) values (1, 1), (2, 2), (5, 5), (10, 10), (11, 11), (NULL, NULL)")
tk.MustExec("admin check index admin_test c1")
tk.MustExec("admin check index admin_test c2")
}
tk.MustExec("drop table if exists admin_test")
tk.MustExec("create table admin_test (c1 int, c2 int, c3 int default 1, index (c1), unique key(c2))")
check()

// Test for hash partition table.
tk.MustExec("drop table if exists admin_test")
tk.MustExec("create table admin_test (c1 int, c2 int, c3 int default 1, index (c1), unique key(c2)) partition by hash(c2) partitions 5;")
check()

// Test for range partition table.
tk.MustExec("drop table if exists admin_test")
tk.MustExec(`create table admin_test (c1 int, c2 int, c3 int default 1, index (c1), unique key(c2)) PARTITION BY RANGE ( c2 ) (
PARTITION p0 VALUES LESS THAN (5),
PARTITION p1 VALUES LESS THAN (10),
PARTITION p2 VALUES LESS THAN (MAXVALUE))`)
check()
}

func TestAdminRecoverIndex(t *testing.T) {
store, domain := testkit.CreateMockStoreAndDomain(t)

Expand Down Expand Up @@ -1788,16 +1741,3 @@ func TestAdminCheckTableErrorLocateForClusterIndex(t *testing.T) {
tk.MustExec("admin check table admin_test")
}
}

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

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists admin_test")
tk.MustExec("create table admin_test (c1 int, c2 int, primary key(c1), key(c2))")
tk.MustExec("set cte_max_recursion_depth=100000;")
tk.MustExec("insert into admin_test with recursive cte(a, b) as (select 1, 1 union select a+1, b+1 from cte where cte.a< 100000) select * from cte;")
tk.MustQuery("select /*+ read_from_storage(tikv[`test`.`admin_test`]) */ bit_xor(crc32(md5(concat_ws(0x2, `c1`, `c2`)))), ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024), count(*) from `test`.`admin_test` use index() where 0 = 0 group by ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024)")
tk.MustQuery("select bit_xor(crc32(md5(concat_ws(0x2, `c1`, `c2`)))), ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024), count(*) from `test`.`admin_test` use index(`c2`) where 0 = 0 group by ((cast(crc32(md5(concat_ws(0x2, `c1`))) as signed) - 9223372036854775807) div 1 % 1024)")
}
2 changes: 1 addition & 1 deletion pkg/executor/test/analyzetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go_test(
"main_test.go",
],
flaky = True,
shard_count = 50,
shard_count = 48,
deps = [
"//pkg/config",
"//pkg/domain",
Expand Down
102 changes: 3 additions & 99 deletions pkg/executor/test/analyzetest/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,38 +122,6 @@ func TestAnalyzeReplicaReadFollower(t *testing.T) {
ctx.GetSessionVars().SetReplicaRead(kv.ReplicaReadFollower)
tk.MustExec("analyze table t")
}

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

tk.MustExec("drop database if exists test_cluster_index_analyze;")
tk.MustExec("create database test_cluster_index_analyze;")
tk.MustExec("use test_cluster_index_analyze;")
tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn

tk.MustExec("create table t (a int, b int, c int, primary key(a, b));")
for i := 0; i < 100; i++ {
tk.MustExec("insert into t values (?, ?, ?)", i, i, i)
}
tk.MustExec("analyze table t;")
tk.MustExec("drop table t;")

tk.MustExec("create table t (a varchar(255), b int, c float, primary key(c, a));")
for i := 0; i < 100; i++ {
tk.MustExec("insert into t values (?, ?, ?)", strconv.Itoa(i), i, i)
}
tk.MustExec("analyze table t;")
tk.MustExec("drop table t;")

tk.MustExec("create table t (a char(10), b decimal(5, 3), c int, primary key(a, c, b));")
for i := 0; i < 100; i++ {
tk.MustExec("insert into t values (?, ?, ?)", strconv.Itoa(i), i, i)
}
tk.MustExec("analyze table t;")
tk.MustExec("drop table t;")
}

func TestAnalyzeRestrict(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down Expand Up @@ -246,28 +214,6 @@ func TestAnalyzeTooLongColumns(t *testing.T) {
require.Equal(t, int64(65559), tbl.Columns[1].TotColSize)
}

func TestAnlyzeIssue(t *testing.T) {
// Issue15993
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("set @@tidb_analyze_version = 1")
tk.MustExec("use test")
tk.MustExec("drop table if exists t0")
tk.MustExec("CREATE TABLE t0(c0 INT PRIMARY KEY);")
tk.MustExec("ANALYZE TABLE t0 INDEX PRIMARY;")
// Issue15751
tk.MustExec("drop table if exists t0")
tk.MustExec("CREATE TABLE t0(c0 INT, c1 INT, PRIMARY KEY(c0, c1))")
tk.MustExec("INSERT INTO t0 VALUES (0, 0)")
tk.MustExec("ANALYZE TABLE t0")
// Issue15752
tk.MustExec("drop table if exists t0")
tk.MustExec("CREATE TABLE t0(c0 INT)")
tk.MustExec("INSERT INTO t0 VALUES (0)")
tk.MustExec("CREATE INDEX i0 ON t0(c0)")
tk.MustExec("ANALYZE TABLE t0 INDEX i0")
}

func TestFailedAnalyzeRequest(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down Expand Up @@ -1517,34 +1463,6 @@ func TestAnalyzeColumnsWithDynamicPartitionTable(t *testing.T) {
}
}

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

tk := testkit.NewTestKit(t, store)
tk.MustExec(`USE test`)
tk.MustExec(`DROP TABLE IF EXISTS Issue34228`)
tk.MustExec(`CREATE TABLE Issue34228 (id bigint NOT NULL, dt datetime NOT NULL) PARTITION BY RANGE COLUMNS(dt) (PARTITION p202201 VALUES LESS THAN ("2022-02-01"), PARTITION p202202 VALUES LESS THAN ("2022-03-01"))`)
tk.MustExec(`INSERT INTO Issue34228 VALUES (1, '2022-02-01 00:00:02'), (2, '2022-02-01 00:00:02')`)
tk.MustExec(`SET @@global.tidb_analyze_version = 1`)
tk.MustExec(`SET @@session.tidb_partition_prune_mode = 'static'`)
tk.MustExec(`ANALYZE TABLE Issue34228`)
tk.MustExec(`SET @@session.tidb_partition_prune_mode = 'dynamic'`)
tk.MustExec(`ANALYZE TABLE Issue34228`)
tk.MustQuery(`SELECT * FROM Issue34228`).Sort().Check(testkit.Rows("1 2022-02-01 00:00:02", "2 2022-02-01 00:00:02"))
// Needs a second run to hit the issue
tk2 := testkit.NewTestKit(t, store)
tk2.MustExec(`USE test`)
tk2.MustExec(`DROP TABLE IF EXISTS Issue34228`)
tk2.MustExec(`CREATE TABLE Issue34228 (id bigint NOT NULL, dt datetime NOT NULL) PARTITION BY RANGE COLUMNS(dt) (PARTITION p202201 VALUES LESS THAN ("2022-02-01"), PARTITION p202202 VALUES LESS THAN ("2022-03-01"))`)
tk2.MustExec(`INSERT INTO Issue34228 VALUES (1, '2022-02-01 00:00:02'), (2, '2022-02-01 00:00:02')`)
tk2.MustExec(`SET @@global.tidb_analyze_version = 1`)
tk2.MustExec(`SET @@session.tidb_partition_prune_mode = 'static'`)
tk2.MustExec(`ANALYZE TABLE Issue34228`)
tk2.MustExec(`SET @@session.tidb_partition_prune_mode = 'dynamic'`)
tk2.MustExec(`ANALYZE TABLE Issue34228`)
tk2.MustQuery(`SELECT * FROM Issue34228`).Sort().Check(testkit.Rows("1 2022-02-01 00:00:02", "2 2022-02-01 00:00:02"))
}

func TestAnalyzeColumnsWithStaticPartitionTable(t *testing.T) {
for _, val := range []model.ColumnChoice{model.ColumnList, model.PredicateColumns} {
func(choice model.ColumnChoice) {
Expand Down Expand Up @@ -2037,11 +1955,10 @@ func testKillAutoAnalyze(t *testing.T, ver int) {
}
}

func TestKillAutoAnalyzeV1(t *testing.T) {
func TestKillAutoAnalyze(t *testing.T) {
// version 1
testKillAutoAnalyze(t, 1)
}

func TestKillAutoAnalyzeV2(t *testing.T) {
// version 2
testKillAutoAnalyze(t, 2)
}

Expand Down Expand Up @@ -2874,19 +2791,6 @@ func TestAnalyzeColumnsSkipMVIndexJsonCol(t *testing.T) {
require.False(t, stats.Indices[tblInfo.Indices[1].ID].IsStatsInitialized())
}

func TestManualAnalyzeSkipColumnTypes(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t(a int, b int, c json, d text, e mediumtext, f blob, g mediumblob, index idx(d(10)))")
tk.MustExec("set @@session.tidb_analyze_skip_column_types = 'json,blob,mediumblob,text,mediumtext'")
tk.MustExec("analyze table t")
tk.MustQuery("select job_info from mysql.analyze_jobs where job_info like '%analyze table%'").Check(testkit.Rows("analyze table columns a, b, d with 256 buckets, 500 topn, 1 samplerate"))
tk.MustExec("delete from mysql.analyze_jobs")
tk.MustExec("analyze table t columns a, e")
tk.MustQuery("select job_info from mysql.analyze_jobs where job_info like '%analyze table%'").Check(testkit.Rows("analyze table columns a, d with 256 buckets, 500 topn, 1 samplerate"))
}

// TestAnalyzeMVIndex tests analyzing the mv index use some real data in the table.
// It checks the analyze jobs, async loading and the stats content in the memory.
func TestAnalyzeMVIndex(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/executor/test/autoidtest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ go_test(
],
flaky = True,
race = "on",
shard_count = 10,
shard_count = 4,
deps = [
"//pkg/autoid_service",
"//pkg/config",
"//pkg/ddl/testutil",
"//pkg/meta/autoid",
"//pkg/parser/mysql",
"//pkg/session",
"//pkg/sessionctx/variable",
"//pkg/testkit",
"//pkg/testkit/testutil",
Expand Down
Loading