Skip to content

Commit

Permalink
*: move IT tests in sessionctx, sessiontxn to integrationtest (#4…
Browse files Browse the repository at this point in the history
…7212)

close #47211, close #47213
  • Loading branch information
Defined2014 authored Sep 25, 2023
1 parent 61a9bce commit 0a04a04
Show file tree
Hide file tree
Showing 9 changed files with 2,523 additions and 283 deletions.
5 changes: 3 additions & 2 deletions sessionctx/binloginfo/binloginfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,11 @@ func TestPessimisticLockThenCommit(t *testing.T) {
}

func TestDeleteSchema(t *testing.T) {
store := testkit.CreateMockStore(t)
s := createBinlogSuite(t)

tk := testkit.NewTestKit(t, store)
tk := testkit.NewTestKit(t, s.store)
tk.MustExec("use test")
tk.Session().GetSessionVars().BinlogClient = s.client
tk.MustExec("CREATE TABLE `b1` (`id` int(11) NOT NULL AUTO_INCREMENT, `job_id` varchar(50) NOT NULL, `split_job_id` varchar(30) DEFAULT NULL, PRIMARY KEY (`id`), KEY `b1` (`job_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;")
tk.MustExec("CREATE TABLE `b2` (`id` int(11) NOT NULL AUTO_INCREMENT, `job_id` varchar(50) NOT NULL, `batch_class` varchar(20) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `bu` (`job_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4")
tk.MustExec("insert into b2 (job_id, batch_class) values (2, 'TEST');")
Expand Down
1 change: 0 additions & 1 deletion sessionctx/variable/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ go_test(
"mock_globalaccessor_test.go",
"removed_test.go",
"session_test.go",
"setvar_test.go",
"statusvar_test.go",
"sysvar_test.go",
"variable_test.go",
Expand Down
186 changes: 0 additions & 186 deletions sessionctx/variable/setvar_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion sessiontxn/staleread/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ go_test(
"provider_test.go",
],
flaky = True,
shard_count = 10,
shard_count = 6,
deps = [
":staleread",
"//domain",
Expand Down
93 changes: 0 additions & 93 deletions sessiontxn/staleread/externalts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,6 @@ import (
"github.com/stretchr/testify/require"
)

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

tk.MustQuery("select @@tidb_external_ts").Check(testkit.Rows("0"))
tk.MustExec("set global tidb_external_ts=19980613")
tk.MustQuery("select @@tidb_external_ts").Check(testkit.Rows("19980613"))
tk.MustExec("set global tidb_external_ts=20220930")
tk.MustQuery("select @@tidb_external_ts").Check(testkit.Rows("20220930"))
}

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

tk.MustExec("use test")
tk.MustExec("create table t (id INT NOT NULL,d double,PRIMARY KEY (id))")
tk.MustExec("insert into t values (0, 100)")
tk.MustExec("insert into t values (1, 100)")
tk.MustExec("insert into t values (2, 100)")
tk.MustExec("insert into t values (3, 100)")
tk.MustQuery("select * from t").Check(testkit.Rows("0 100", "1 100", "2 100", "3 100"))

tk.MustQuery("select @@tidb_external_ts").Check(testkit.Rows("0"))
tk.MustExec("start transaction;set global tidb_external_ts=@@tidb_current_ts;commit;")
tk.MustExec("insert into t values (4, 100)")
// as the `tidb_external_ts` is set an old value, the newest row (4, 100) cannot be read
tk.MustExec("set tidb_enable_external_ts_read=ON")
tk.MustQuery("select * from t").Check(testkit.Rows("0 100", "1 100", "2 100", "3 100"))

tk.MustExec("set tidb_enable_external_ts_read=OFF")
tk.MustQuery("select * from t").Check(testkit.Rows("0 100", "1 100", "2 100", "3 100", "4 100"))
}

func TestExternalTimestampReadonly(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand All @@ -84,62 +50,3 @@ func TestExternalTimestampReadonly(t *testing.T) {
tk.MustExecWithContext(ctx, "insert into t values (1)")
tk.Session().GetSessionVars().InRestrictedSQL = false
}

func TestExternalTimestampReadWithTransaction(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil))

tk.MustExec("use test")
tk.MustExec("create table t (id INT NOT NULL,PRIMARY KEY (id))")

tk.MustQuery("select @@tidb_external_ts").Check(testkit.Rows("0"))
tk.MustExec("start transaction;set global tidb_external_ts=@@tidb_current_ts;commit;")

tk.MustExec("insert into t values (0)")
tk.MustQuery("select * from t").Check(testkit.Rows("0"))

tk.MustExec("set tidb_enable_external_ts_read=ON")
tk.MustQuery("select * from t").Check(testkit.Rows())
tk.MustExec("start transaction")
tk.MustQuery("select * from t").Check(testkit.Rows())
tk.MustExec("commit")

tk.MustExec("set tidb_enable_external_ts_read=OFF")
tk.MustExec("start transaction")
tk.MustQuery("select * from t").Check(testkit.Rows("0"))
tk.MustExec("commit")

tk.MustExec("start transaction")
tk.MustQuery("select * from t").Check(testkit.Rows("0"))
tk.MustExec("set tidb_enable_external_ts_read=ON")
// `tidb_enable_external_ts_read` doesn't affect existing transaction
tk.MustQuery("select * from t").Check(testkit.Rows("0"))
tk.MustExec("set tidb_enable_external_ts_read=OFF")
tk.MustExec("commit")
}

func TestExternalTimestampNotAffectPrepare(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil))

tk.MustExec("use test")
tk.MustExec("create table t (id INT NOT NULL,PRIMARY KEY (id))")

tk.MustExec("insert into t values (0)")
tk.MustQuery("select * from t").Check(testkit.Rows("0"))

tk.MustQuery("select @@tidb_external_ts").Check(testkit.Rows("0"))
tk.MustExec("start transaction;set global tidb_external_ts=@@tidb_current_ts;commit;")

tk.MustExec("insert into t values (1)")
tk.MustQuery("select * from t").Check(testkit.Rows("0", "1"))

tk.MustExec("set tidb_enable_external_ts_read=on")
tk.MustExec("prepare my_select from 'select * from t'")
tk.MustQuery("execute my_select").Check(testkit.Rows("0"))
tk.MustExec("set tidb_enable_external_ts_read=off")

tk.MustQuery("execute my_select").Check(testkit.Rows("0", "1"))
}
Loading

0 comments on commit 0a04a04

Please sign in to comment.