Skip to content

Commit

Permalink
tests: move TestNoopFunctions to tests/integrationtest (pingcap#5…
Browse files Browse the repository at this point in the history
  • Loading branch information
henrybw authored May 17, 2024
1 parent 9c89227 commit 9581442
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 67 deletions.
2 changes: 1 addition & 1 deletion pkg/expression/integration_test/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 = 27,
shard_count = 26,
deps = [
"//pkg/config",
"//pkg/domain",
Expand Down
66 changes: 0 additions & 66 deletions pkg/expression/integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2771,72 +2771,6 @@ func TestIssue16205(t *testing.T) {
require.NotEqual(t, rows1[0][0].(string), rows2[0][0].(string))
}

// issues 14448, 19383, 17734
func TestNoopFunctions(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`set tidb_enable_non_prepared_plan_cache=0`) // variable changes in the test will not affect the plan cache
tk.MustExec("DROP TABLE IF EXISTS t1")
tk.MustExec("CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY)")
tk.MustExec("INSERT INTO t1 VALUES (1),(2),(3)")

message := `.* has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions`
stmts := []string{
"SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1",
"SELECT * FROM t1 LOCK IN SHARE MODE",
"SELECT * FROM t1 GROUP BY a DESC",
"SELECT * FROM t1 GROUP BY a ASC",
}

for _, stmt := range stmts {
// test on
tk.MustExec("SET tidb_enable_noop_functions='ON'")
tk.MustExec(stmt)
// test warning
tk.MustExec("SET tidb_enable_noop_functions='WARN'")
tk.MustExec(stmt)
warn := tk.Session().GetSessionVars().StmtCtx.GetWarnings()
require.Regexp(t, message, warn[0].Err.Error())
// test off
tk.MustExec("SET tidb_enable_noop_functions='OFF'")
_, err := tk.Exec(stmt)
require.Regexp(t, message, err.Error())
}

// These statements return a different error message
// to the above. Test for error, not specifically the message.
// After they execute, we need to reset the values because
// otherwise tidb_enable_noop_functions can't be changed.

stmts = []string{
"START TRANSACTION READ ONLY",
"SET TRANSACTION READ ONLY",
"SET tx_read_only = 1",
"SET transaction_read_only = 1",
}

for _, stmt := range stmts {
// test off
tk.MustExec("SET tidb_enable_noop_functions='OFF'")
_, err := tk.Exec(stmt)
require.Error(t, err)
// test warning
tk.MustExec("SET tidb_enable_noop_functions='WARN'")
tk.MustExec(stmt)
warn := tk.Session().GetSessionVars().StmtCtx.GetWarnings()
require.Len(t, warn, 1)
// test on
tk.MustExec("SET tidb_enable_noop_functions='ON'")
tk.MustExec(stmt)

// Reset (required for future loop iterations and future tests)
tk.MustExec("SET tx_read_only = 0")
tk.MustExec("SET transaction_read_only = 0")
}
}

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

Expand Down
79 changes: 79 additions & 0 deletions tests/integrationtest/r/expression/noop_functions.result
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ a
SELECT * FROM t1 WHERE a=1 LOCK IN SHARE MODE;
a
1
SELECT * FROM t1 GROUP BY a DESC;
a
1
2
3
SELECT * FROM t1 GROUP BY a ASC;
a
1
2
3
SET @@tidb_enable_noop_functions='WARN';
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1;
a
Expand All @@ -32,10 +42,79 @@ a
1
Level Code Message
Warning 1235 function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SELECT * FROM t1 GROUP BY a DESC;
a
1
2
3
Level Code Message
Warning 1235 function GROUP BY expr ASC|DESC has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SELECT * FROM t1 GROUP BY a ASC;
a
1
2
3
Level Code Message
Warning 1235 function GROUP BY expr ASC|DESC has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SET @@tidb_enable_noop_functions='OFF';
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1;
Error 1235 (42000): function SQL_CALC_FOUND_ROWS has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SELECT * FROM t1 LOCK IN SHARE MODE;
Error 1235 (42000): function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SELECT * FROM t1 WHERE a=1 LOCK IN SHARE MODE;
Error 1235 (42000): function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SELECT * FROM t1 GROUP BY a DESC;
Error 1235 (42000): function GROUP BY expr ASC|DESC has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SELECT * FROM t1 GROUP BY a ASC;
Error 1235 (42000): function GROUP BY expr ASC|DESC has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SET @@tidb_enable_noop_functions='ON';
START TRANSACTION READ ONLY;
SET tx_read_only = 0;
SET transaction_read_only = 0;
SET TRANSACTION READ ONLY;
SET tx_read_only = 0;
SET transaction_read_only = 0;
SET tx_read_only = 1;
SET tx_read_only = 0;
SET transaction_read_only = 0;
SET transaction_read_only = 1;
SET tx_read_only = 0;
SET transaction_read_only = 0;
SET @@tidb_enable_noop_functions='WARN';
START TRANSACTION READ ONLY;
Level Code Message
Warning 1235 function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SET tx_read_only = 0;
SET transaction_read_only = 0;
SET TRANSACTION READ ONLY;
Level Code Message
Warning 1235 function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SET tx_read_only = 0;
SET transaction_read_only = 0;
SET tx_read_only = 1;
Level Code Message
Warning 1235 function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SET tx_read_only = 0;
SET transaction_read_only = 0;
SET transaction_read_only = 1;
Level Code Message
Warning 1235 function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SET tx_read_only = 0;
SET transaction_read_only = 0;
SET @@tidb_enable_noop_functions='OFF';
START TRANSACTION READ ONLY;
Error 1235 (42000): function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SET tx_read_only = 0;
SET transaction_read_only = 0;
SET TRANSACTION READ ONLY;
Error 1235 (42000): function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SET tx_read_only = 0;
SET transaction_read_only = 0;
SET tx_read_only = 1;
Error 1235 (42000): function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SET tx_read_only = 0;
SET transaction_read_only = 0;
SET transaction_read_only = 1;
Error 1235 (42000): function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
SET tx_read_only = 0;
SET transaction_read_only = 0;
74 changes: 74 additions & 0 deletions tests/integrationtest/t/expression/noop_functions.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# TestNoopFunctions
# issues 14448, 19383, 17734, 52432

# variable changes in the test will not affect the plan cache
set tidb_enable_non_prepared_plan_cache=0;
DROP TABLE IF EXISTS t1;
Expand All @@ -9,12 +12,16 @@ SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1;
SELECT * FROM t1 LOCK IN SHARE MODE;
# test the fast path for point-get queries
SELECT * FROM t1 WHERE a=1 LOCK IN SHARE MODE;
SELECT * FROM t1 GROUP BY a DESC;
SELECT * FROM t1 GROUP BY a ASC;

SET @@tidb_enable_noop_functions='WARN';
--enable_warnings
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1;
SELECT * FROM t1 LOCK IN SHARE MODE;
SELECT * FROM t1 WHERE a=1 LOCK IN SHARE MODE;
SELECT * FROM t1 GROUP BY a DESC;
SELECT * FROM t1 GROUP BY a ASC;
--disable_warnings

SET @@tidb_enable_noop_functions='OFF';
Expand All @@ -24,3 +31,70 @@ SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1;
SELECT * FROM t1 LOCK IN SHARE MODE;
--error 1235
SELECT * FROM t1 WHERE a=1 LOCK IN SHARE MODE;
--error 1235
SELECT * FROM t1 GROUP BY a DESC;
--error 1235
SELECT * FROM t1 GROUP BY a ASC;

# After each of these statements execute, we need to reset the values
# because otherwise tidb_enable_noop_functions can't be changed.

SET @@tidb_enable_noop_functions='ON';

START TRANSACTION READ ONLY;
SET tx_read_only = 0;
SET transaction_read_only = 0;

SET TRANSACTION READ ONLY;
SET tx_read_only = 0;
SET transaction_read_only = 0;

SET tx_read_only = 1;
SET tx_read_only = 0;
SET transaction_read_only = 0;

SET transaction_read_only = 1;
SET tx_read_only = 0;
SET transaction_read_only = 0;

SET @@tidb_enable_noop_functions='WARN';

--enable_warnings
START TRANSACTION READ ONLY;
SET tx_read_only = 0;
SET transaction_read_only = 0;

SET TRANSACTION READ ONLY;
SET tx_read_only = 0;
SET transaction_read_only = 0;

SET tx_read_only = 1;
SET tx_read_only = 0;
SET transaction_read_only = 0;

SET transaction_read_only = 1;
SET tx_read_only = 0;
SET transaction_read_only = 0;
--disable_warnings

SET @@tidb_enable_noop_functions='OFF';

--error 1235
START TRANSACTION READ ONLY;
SET tx_read_only = 0;
SET transaction_read_only = 0;

--error 1235
SET TRANSACTION READ ONLY;
SET tx_read_only = 0;
SET transaction_read_only = 0;

--error 1235
SET tx_read_only = 1;
SET tx_read_only = 0;
SET transaction_read_only = 0;

--error 1235
SET transaction_read_only = 1;
SET tx_read_only = 0;
SET transaction_read_only = 0;

0 comments on commit 9581442

Please sign in to comment.