Skip to content

Commit 9581442

Browse files
authored
tests: move TestNoopFunctions to tests/integrationtest (#53343)
ref #45961
1 parent 9c89227 commit 9581442

File tree

4 files changed

+154
-67
lines changed

4 files changed

+154
-67
lines changed

pkg/expression/integration_test/BUILD.bazel

+1-1
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 = 27,
11+
shard_count = 26,
1212
deps = [
1313
"//pkg/config",
1414
"//pkg/domain",

pkg/expression/integration_test/integration_test.go

-66
Original file line numberDiff line numberDiff line change
@@ -2771,72 +2771,6 @@ func TestIssue16205(t *testing.T) {
27712771
require.NotEqual(t, rows1[0][0].(string), rows2[0][0].(string))
27722772
}
27732773

2774-
// issues 14448, 19383, 17734
2775-
func TestNoopFunctions(t *testing.T) {
2776-
store := testkit.CreateMockStore(t)
2777-
2778-
tk := testkit.NewTestKit(t, store)
2779-
tk.MustExec("use test")
2780-
tk.MustExec(`set tidb_enable_non_prepared_plan_cache=0`) // variable changes in the test will not affect the plan cache
2781-
tk.MustExec("DROP TABLE IF EXISTS t1")
2782-
tk.MustExec("CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY)")
2783-
tk.MustExec("INSERT INTO t1 VALUES (1),(2),(3)")
2784-
2785-
message := `.* has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions`
2786-
stmts := []string{
2787-
"SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1",
2788-
"SELECT * FROM t1 LOCK IN SHARE MODE",
2789-
"SELECT * FROM t1 GROUP BY a DESC",
2790-
"SELECT * FROM t1 GROUP BY a ASC",
2791-
}
2792-
2793-
for _, stmt := range stmts {
2794-
// test on
2795-
tk.MustExec("SET tidb_enable_noop_functions='ON'")
2796-
tk.MustExec(stmt)
2797-
// test warning
2798-
tk.MustExec("SET tidb_enable_noop_functions='WARN'")
2799-
tk.MustExec(stmt)
2800-
warn := tk.Session().GetSessionVars().StmtCtx.GetWarnings()
2801-
require.Regexp(t, message, warn[0].Err.Error())
2802-
// test off
2803-
tk.MustExec("SET tidb_enable_noop_functions='OFF'")
2804-
_, err := tk.Exec(stmt)
2805-
require.Regexp(t, message, err.Error())
2806-
}
2807-
2808-
// These statements return a different error message
2809-
// to the above. Test for error, not specifically the message.
2810-
// After they execute, we need to reset the values because
2811-
// otherwise tidb_enable_noop_functions can't be changed.
2812-
2813-
stmts = []string{
2814-
"START TRANSACTION READ ONLY",
2815-
"SET TRANSACTION READ ONLY",
2816-
"SET tx_read_only = 1",
2817-
"SET transaction_read_only = 1",
2818-
}
2819-
2820-
for _, stmt := range stmts {
2821-
// test off
2822-
tk.MustExec("SET tidb_enable_noop_functions='OFF'")
2823-
_, err := tk.Exec(stmt)
2824-
require.Error(t, err)
2825-
// test warning
2826-
tk.MustExec("SET tidb_enable_noop_functions='WARN'")
2827-
tk.MustExec(stmt)
2828-
warn := tk.Session().GetSessionVars().StmtCtx.GetWarnings()
2829-
require.Len(t, warn, 1)
2830-
// test on
2831-
tk.MustExec("SET tidb_enable_noop_functions='ON'")
2832-
tk.MustExec(stmt)
2833-
2834-
// Reset (required for future loop iterations and future tests)
2835-
tk.MustExec("SET tx_read_only = 0")
2836-
tk.MustExec("SET transaction_read_only = 0")
2837-
}
2838-
}
2839-
28402774
func TestCrossDCQuery(t *testing.T) {
28412775
store := testkit.CreateMockStore(t)
28422776

tests/integrationtest/r/expression/noop_functions.result

+79
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ a
1414
SELECT * FROM t1 WHERE a=1 LOCK IN SHARE MODE;
1515
a
1616
1
17+
SELECT * FROM t1 GROUP BY a DESC;
18+
a
19+
1
20+
2
21+
3
22+
SELECT * FROM t1 GROUP BY a ASC;
23+
a
24+
1
25+
2
26+
3
1727
SET @@tidb_enable_noop_functions='WARN';
1828
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1;
1929
a
@@ -32,10 +42,79 @@ a
3242
1
3343
Level Code Message
3444
Warning 1235 function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
45+
SELECT * FROM t1 GROUP BY a DESC;
46+
a
47+
1
48+
2
49+
3
50+
Level Code Message
51+
Warning 1235 function GROUP BY expr ASC|DESC has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
52+
SELECT * FROM t1 GROUP BY a ASC;
53+
a
54+
1
55+
2
56+
3
57+
Level Code Message
58+
Warning 1235 function GROUP BY expr ASC|DESC has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
3559
SET @@tidb_enable_noop_functions='OFF';
3660
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1;
3761
Error 1235 (42000): function SQL_CALC_FOUND_ROWS has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
3862
SELECT * FROM t1 LOCK IN SHARE MODE;
3963
Error 1235 (42000): function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
4064
SELECT * FROM t1 WHERE a=1 LOCK IN SHARE MODE;
4165
Error 1235 (42000): function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
66+
SELECT * FROM t1 GROUP BY a DESC;
67+
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
68+
SELECT * FROM t1 GROUP BY a ASC;
69+
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
70+
SET @@tidb_enable_noop_functions='ON';
71+
START TRANSACTION READ ONLY;
72+
SET tx_read_only = 0;
73+
SET transaction_read_only = 0;
74+
SET TRANSACTION READ ONLY;
75+
SET tx_read_only = 0;
76+
SET transaction_read_only = 0;
77+
SET tx_read_only = 1;
78+
SET tx_read_only = 0;
79+
SET transaction_read_only = 0;
80+
SET transaction_read_only = 1;
81+
SET tx_read_only = 0;
82+
SET transaction_read_only = 0;
83+
SET @@tidb_enable_noop_functions='WARN';
84+
START TRANSACTION READ ONLY;
85+
Level Code Message
86+
Warning 1235 function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
87+
SET tx_read_only = 0;
88+
SET transaction_read_only = 0;
89+
SET TRANSACTION READ ONLY;
90+
Level Code Message
91+
Warning 1235 function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
92+
SET tx_read_only = 0;
93+
SET transaction_read_only = 0;
94+
SET tx_read_only = 1;
95+
Level Code Message
96+
Warning 1235 function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
97+
SET tx_read_only = 0;
98+
SET transaction_read_only = 0;
99+
SET transaction_read_only = 1;
100+
Level Code Message
101+
Warning 1235 function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
102+
SET tx_read_only = 0;
103+
SET transaction_read_only = 0;
104+
SET @@tidb_enable_noop_functions='OFF';
105+
START TRANSACTION READ ONLY;
106+
Error 1235 (42000): function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
107+
SET tx_read_only = 0;
108+
SET transaction_read_only = 0;
109+
SET TRANSACTION READ ONLY;
110+
Error 1235 (42000): function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
111+
SET tx_read_only = 0;
112+
SET transaction_read_only = 0;
113+
SET tx_read_only = 1;
114+
Error 1235 (42000): function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
115+
SET tx_read_only = 0;
116+
SET transaction_read_only = 0;
117+
SET transaction_read_only = 1;
118+
Error 1235 (42000): function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
119+
SET tx_read_only = 0;
120+
SET transaction_read_only = 0;

tests/integrationtest/t/expression/noop_functions.test

+74
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# TestNoopFunctions
2+
# issues 14448, 19383, 17734, 52432
3+
14
# variable changes in the test will not affect the plan cache
25
set tidb_enable_non_prepared_plan_cache=0;
36
DROP TABLE IF EXISTS t1;
@@ -9,12 +12,16 @@ SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1;
912
SELECT * FROM t1 LOCK IN SHARE MODE;
1013
# test the fast path for point-get queries
1114
SELECT * FROM t1 WHERE a=1 LOCK IN SHARE MODE;
15+
SELECT * FROM t1 GROUP BY a DESC;
16+
SELECT * FROM t1 GROUP BY a ASC;
1217

1318
SET @@tidb_enable_noop_functions='WARN';
1419
--enable_warnings
1520
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1;
1621
SELECT * FROM t1 LOCK IN SHARE MODE;
1722
SELECT * FROM t1 WHERE a=1 LOCK IN SHARE MODE;
23+
SELECT * FROM t1 GROUP BY a DESC;
24+
SELECT * FROM t1 GROUP BY a ASC;
1825
--disable_warnings
1926

2027
SET @@tidb_enable_noop_functions='OFF';
@@ -24,3 +31,70 @@ SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1;
2431
SELECT * FROM t1 LOCK IN SHARE MODE;
2532
--error 1235
2633
SELECT * FROM t1 WHERE a=1 LOCK IN SHARE MODE;
34+
--error 1235
35+
SELECT * FROM t1 GROUP BY a DESC;
36+
--error 1235
37+
SELECT * FROM t1 GROUP BY a ASC;
38+
39+
# After each of these statements execute, we need to reset the values
40+
# because otherwise tidb_enable_noop_functions can't be changed.
41+
42+
SET @@tidb_enable_noop_functions='ON';
43+
44+
START TRANSACTION READ ONLY;
45+
SET tx_read_only = 0;
46+
SET transaction_read_only = 0;
47+
48+
SET TRANSACTION READ ONLY;
49+
SET tx_read_only = 0;
50+
SET transaction_read_only = 0;
51+
52+
SET tx_read_only = 1;
53+
SET tx_read_only = 0;
54+
SET transaction_read_only = 0;
55+
56+
SET transaction_read_only = 1;
57+
SET tx_read_only = 0;
58+
SET transaction_read_only = 0;
59+
60+
SET @@tidb_enable_noop_functions='WARN';
61+
62+
--enable_warnings
63+
START TRANSACTION READ ONLY;
64+
SET tx_read_only = 0;
65+
SET transaction_read_only = 0;
66+
67+
SET TRANSACTION READ ONLY;
68+
SET tx_read_only = 0;
69+
SET transaction_read_only = 0;
70+
71+
SET tx_read_only = 1;
72+
SET tx_read_only = 0;
73+
SET transaction_read_only = 0;
74+
75+
SET transaction_read_only = 1;
76+
SET tx_read_only = 0;
77+
SET transaction_read_only = 0;
78+
--disable_warnings
79+
80+
SET @@tidb_enable_noop_functions='OFF';
81+
82+
--error 1235
83+
START TRANSACTION READ ONLY;
84+
SET tx_read_only = 0;
85+
SET transaction_read_only = 0;
86+
87+
--error 1235
88+
SET TRANSACTION READ ONLY;
89+
SET tx_read_only = 0;
90+
SET transaction_read_only = 0;
91+
92+
--error 1235
93+
SET tx_read_only = 1;
94+
SET tx_read_only = 0;
95+
SET transaction_read_only = 0;
96+
97+
--error 1235
98+
SET transaction_read_only = 1;
99+
SET tx_read_only = 0;
100+
SET transaction_read_only = 0;

0 commit comments

Comments
 (0)