Skip to content

Commit

Permalink
tests: Update mysql-tester, move tests related with RowsAffected an…
Browse files Browse the repository at this point in the history
…d `LastMessage` (#48789)

ref #45961
  • Loading branch information
Defined2014 authored Nov 23, 2023
1 parent 204c9ac commit 077a3e9
Show file tree
Hide file tree
Showing 40 changed files with 5,411 additions and 2,769 deletions.
6 changes: 0 additions & 6 deletions pkg/executor/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ import (
"github.com/stretchr/testify/require"
)

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

func TestInsertOnDuplicateKeyWithBinlog(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
9 changes: 0 additions & 9 deletions pkg/executor/internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "internal",
srcs = ["testkit.go"],
importpath = "github.com/pingcap/tidb/pkg/executor/internal",
visibility = ["//pkg/executor:__subpackages__"],
deps = ["//pkg/testkit"],
)
31 changes: 0 additions & 31 deletions pkg/executor/internal/testkit.go

This file was deleted.

15 changes: 0 additions & 15 deletions pkg/executor/stale_txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1315,21 +1315,6 @@ func TestPlanCacheWithStaleReadByBinaryProto(t *testing.T) {
tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 10"))
}

func TestIssue33728(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)")
err := tk.ExecToErr("select * from t1 as of timestamp NULL")
require.Error(t, err)
require.Equal(t, "[planner:8135]invalid as of timestamp: as of timestamp cannot be NULL", err.Error())

err = tk.ExecToErr("start transaction read only as of timestamp NULL")
require.Error(t, err)
require.Equal(t, "[planner:8135]invalid as of timestamp: as of timestamp cannot be NULL", err.Error())
}

func TestStalePrepare(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
3 changes: 1 addition & 2 deletions pkg/executor/test/executor/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 = 46,
deps = [
"//pkg/config",
"//pkg/ddl",
Expand All @@ -32,7 +32,6 @@ go_test(
"//pkg/sessionctx/stmtctx",
"//pkg/sessionctx/variable",
"//pkg/sessiontxn",
"//pkg/store/driver/error",
"//pkg/store/mockstore",
"//pkg/table/tables",
"//pkg/tablecodec",
Expand Down
228 changes: 0 additions & 228 deletions pkg/executor/test/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import (
"github.com/pingcap/tidb/pkg/sessionctx/stmtctx"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/sessiontxn"
error2 "github.com/pingcap/tidb/pkg/store/driver/error"
"github.com/pingcap/tidb/pkg/store/mockstore"
"github.com/pingcap/tidb/pkg/table/tables"
"github.com/pingcap/tidb/pkg/tablecodec"
Expand Down Expand Up @@ -633,117 +632,6 @@ func TestTiDBLastQueryInfo(t *testing.T) {
tk.MustExec("rollback")
}

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

setTxnTk := testkit.NewTestKit(t, store)
setTxnTk.MustExec("set global tidb_txn_mode=''")
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk1 := testkit.NewTestKit(t, store)
tk1.MustExec("use test")
tk2 := testkit.NewTestKit(t, store)
tk2.MustExec("use test")

tk.MustExec("drop table if exists t, t1")

txn, err := tk.Session().Txn(true)
require.True(t, kv.ErrInvalidTxn.Equal(err))
require.False(t, txn.Valid())
tk.MustExec("create table t (c1 int, c2 int, c3 int)")
tk.MustExec("insert t values (11, 2, 3)")
tk.MustExec("insert t values (12, 2, 3)")
tk.MustExec("insert t values (13, 2, 3)")

tk.MustExec("create table t1 (c1 int)")
tk.MustExec("insert t1 values (11)")

// conflict
tk1.MustExec("begin")
tk1.MustQuery("select * from t where c1=11 for update")

tk2.MustExec("begin")
tk2.MustExec("update t set c2=211 where c1=11")
tk2.MustExec("commit")

err = tk1.ExecToErr("commit")
require.Error(t, err)

// no conflict for subquery.
tk1.MustExec("begin")
tk1.MustQuery("select * from t where exists(select null from t1 where t1.c1=t.c1) for update")

tk2.MustExec("begin")
tk2.MustExec("update t set c2=211 where c1=12")
tk2.MustExec("commit")

tk1.MustExec("commit")

// not conflict
tk1.MustExec("begin")
tk1.MustQuery("select * from t where c1=11 for update")

tk2.MustExec("begin")
tk2.MustExec("update t set c2=22 where c1=12")
tk2.MustExec("commit")

tk1.MustExec("commit")

// not conflict, auto commit
tk1.MustExec("set @@autocommit=1;")
tk1.MustQuery("select * from t where c1=11 for update")

tk2.MustExec("begin")
tk2.MustExec("update t set c2=211 where c1=11")
tk2.MustExec("commit")

tk1.MustExec("commit")

// conflict
tk1.MustExec("begin")
tk1.MustQuery("select * from (select * from t for update) t join t1 for update")

tk2.MustExec("begin")
tk2.MustExec("update t1 set c1 = 13")
tk2.MustExec("commit")

err = tk1.ExecToErr("commit")
require.Error(t, err)
}

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

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk1 := testkit.NewTestKit(t, store)
tk1.MustExec("use test")

tk.MustExec("drop table if exists t, t1")
tk.MustExec("create table t (i int)")
tk.MustExec("create table t1 (i int)")
tk.MustExec("insert t values (1)")
tk.MustExec("insert t1 values (1)")

tk.MustExec("begin pessimistic")
tk.MustQuery("select * from t, t1 where t.i = t1.i for update of t").Check(testkit.Rows("1 1"))

tk1.MustExec("begin pessimistic")

// no lock for t
tk1.MustQuery("select * from t1 for update").Check(testkit.Rows("1"))

// meet lock for t1
err := tk1.ExecToErr("select * from t for update nowait")
require.True(t, terror.ErrorEqual(err, error2.ErrLockAcquireFailAndNoWaitSet), fmt.Sprintf("err: %v", err))

// t1 rolled back, tk1 acquire the lock
tk.MustExec("rollback")
tk1.MustQuery("select * from t for update nowait").Check(testkit.Rows("1"))

tk1.MustExec("rollback")
}

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

Expand All @@ -763,37 +651,6 @@ func TestPartitionHashCode(t *testing.T) {
wg.Wait()
}

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

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t1 (a int, b int, index(a))")
tk.MustExec("insert into t1 values (1,2),(2,3),(3,4)")
rows := tk.MustQuery("explain analyze select * from t1 use index(a) where a > 1").Rows()
require.Len(t, rows, 3)
explain := fmt.Sprintf("%v", rows[0])
require.Regexp(t, ".*time:.*loops:.*index_task:.*table_task: {total_time.*num.*concurrency.*}.*", explain)
indexExplain := fmt.Sprintf("%v", rows[1])
tableExplain := fmt.Sprintf("%v", rows[2])
require.Regexp(t, ".*time:.*loops:.*cop_task:.*", indexExplain)
require.Regexp(t, ".*time:.*loops:.*cop_task:.*", tableExplain)
}

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

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t1 (a int, b int)")
tk.MustExec("insert into t1 values (1,2),(2,3),(3,4)")
rows := tk.MustQuery("explain analyze SELECT /*+ HASH_AGG() */ count(*) FROM t1 WHERE a < 10;").Rows()
require.Len(t, rows, 5)
explain := fmt.Sprintf("%v", rows[0])
pattern := ".*time:.*loops:.*partial_worker:{wall_time:.*concurrency:.*task_num:.*tot_wait:.*tot_exec:.*tot_time:.*max:.*p95:.*}.*final_worker:{wall_time:.*concurrency:.*task_num:.*tot_wait:.*tot_exec:.*tot_time:.*max:.*p95:.*}.*"
require.Regexp(t, pattern, explain)
}

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

Expand Down Expand Up @@ -1681,24 +1538,6 @@ func TestAdminShowDDLJobs(t *testing.T) {
require.Equal(t, t2.In(time.UTC), tt.In(time.UTC))
}

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

// Test for issue: https://github.com/pingcap/tidb/issues/25968
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (id bigint key,b int);")
tk.MustExec("split table t by (10),(20),(30);")
tk.MustExec("insert into t values (0,0),(10,10),(20,20),(30,30);")
tk.MustExec("alter table t add index idx1(b);")
require.Equal(t, "4", tk.MustQuery("admin show ddl jobs 1").Rows()[0][7])

tk.MustExec("insert into t values (1,0),(2,10),(3,20),(4,30);")
tk.MustExec("alter table t add index idx2(b);")
require.Equal(t, "8", tk.MustQuery("admin show ddl jobs 1").Rows()[0][7])
}

func TestAdminShowDDLJobsInfo(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down Expand Up @@ -2015,16 +1854,6 @@ func TestLowResolutionTSORead(t *testing.T) {
tk.MustQuery("select * from low_resolution_tso").Check(testkit.Rows("2"))
}

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

tk := testkit.NewTestKit(t, store)
// Setting tx_read_ts to a time in the future will fail. (One day before the 2038 problem)
tk.MustGetErrMsg("set @@tx_read_ts = '2038-01-18 03:14:07'", "cannot set read timestamp to a future time")
// TxnReadTS Is not updated if check failed.
require.Zero(t, tk.Session().GetSessionVars().TxnReadTS.PeakTxnReadTS())
}

func TestAdapterStatement(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down Expand Up @@ -2692,40 +2521,6 @@ func TestAdmin(t *testing.T) {
require.Equal(t, historyJobs2, historyJobs)
}

func TestForSelectScopeInUnion(t *testing.T) {
store := testkit.CreateMockStore(t)
setTxnTk := testkit.NewTestKit(t, store)
setTxnTk.MustExec("set global tidb_txn_mode=''")
// A union B for update, the "for update" option belongs to union statement, so
// it should works on both A and B.
tk1 := testkit.NewTestKit(t, store)
tk2 := testkit.NewTestKit(t, store)
tk1.MustExec("use test")
tk1.MustExec("drop table if exists t")
tk1.MustExec("create table t(a int)")
tk1.MustExec("insert into t values (1)")

tk1.MustExec("begin")
// 'For update' would act on the second select.
tk1.MustQuery("select 1 as a union select a from t for update")

tk2.MustExec("use test")
tk2.MustExec("update t set a = a + 1")

// As tk1 use select 'for update', it should detect conflict and fail.
_, err := tk1.Exec("commit")
require.Error(t, err)

tk1.MustExec("begin")
tk1.MustQuery("select 1 as a union select a from t limit 5 for update")
tk1.MustQuery("select 1 as a union select a from t order by a for update")

tk2.MustExec("update t set a = a + 1")

_, err = tk1.Exec("commit")
require.Error(t, err)
}

func TestMaxOneRow(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand All @@ -2746,29 +2541,6 @@ func TestMaxOneRow(t *testing.T) {
require.NoError(t, rs.Close())
}

func TestSummaryFailedUpdate(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int as(-a))")
tk.MustExec("insert into t(a) values(1), (3), (7)")
sm := &testkit.MockSessionManager{
PS: make([]*util.ProcessInfo, 0),
}
tk.Session().SetSessionManager(sm)
dom.ExpensiveQueryHandle().SetSessionManager(sm)
defer tk.MustExec("SET GLOBAL tidb_mem_oom_action = DEFAULT")
tk.MustQuery("select variable_value from mysql.GLOBAL_VARIABLES where variable_name = 'tidb_mem_oom_action'").Check(testkit.Rows("LOG"))

tk.MustExec("SET GLOBAL tidb_mem_oom_action='CANCEL'")
require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil))
tk.MustExec("set @@tidb_mem_quota_query=1")
require.True(t, exeerrors.ErrMemoryExceedForQuery.Equal(tk.ExecToErr("update t set t.a = t.a - 1 where t.a in (select a from t where a < 4)")))
tk.MustExec("set @@tidb_mem_quota_query=1000000000")
tk.MustQuery("select stmt_type from information_schema.statements_summary where digest_text = 'update `t` set `t` . `a` = `t` . `a` - ? where `t` . `a` in ( select `a` from `t` where `a` < ? )'").Check(testkit.Rows("Update"))
}

func TestIsFastPlan(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
18 changes: 0 additions & 18 deletions pkg/executor/test/partitiontest/BUILD.bazel

This file was deleted.

Loading

0 comments on commit 077a3e9

Please sign in to comment.