Skip to content

Commit

Permalink
tests: fix some test cases in real TiKV env (pingcap#47697)
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 authored and wuhuizuo committed Apr 2, 2024
1 parent 9b58380 commit e542b87
Show file tree
Hide file tree
Showing 18 changed files with 149 additions and 224 deletions.
9 changes: 9 additions & 0 deletions pkg/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ import (
"github.com/stretchr/testify/require"
)

func TestChangePumpAndDrainer(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
// change pump or drainer's state need connect to etcd
// so will meet error "URL scheme must be http, https, unix, or unixs: /tmp/tidb"
tk.MustMatchErrMsg("change pump to node_state ='paused' for node_id 'pump1'", "URL scheme must be http, https, unix, or unixs.*")
tk.MustMatchErrMsg("change drainer to node_state ='paused' for node_id 'drainer1'", "URL scheme must be http, https, unix, or unixs.*")
}

func TestSetOperationOnDiffColType(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
2 changes: 1 addition & 1 deletion pkg/session/test/vars/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_test(
"vars_test.go",
],
flaky = True,
shard_count = 7,
shard_count = 8,
deps = [
"//pkg/config",
"//pkg/domain",
Expand Down
52 changes: 52 additions & 0 deletions pkg/session/test/vars/vars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,58 @@ func TestRemovedSysVars(t *testing.T) {
tk.MustContainErrMsg("SELECT @@GLOBAL.bogus_var", "[variable:1193]Unknown system variable 'bogus_var'")
}

func TestTiKVSystemVars(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")

result := tk.MustQuery("SHOW GLOBAL VARIABLES LIKE 'tidb_gc_enable'") // default is on from the sysvar
result.Check(testkit.Rows("tidb_gc_enable ON"))
result = tk.MustQuery("SELECT variable_value FROM mysql.tidb WHERE variable_name = 'tikv_gc_enable'")
result.Check(testkit.Rows()) // but no value in the table (yet) because the value has not been set and the GC has never been run

// update will set a value in the table
tk.MustExec("SET GLOBAL tidb_gc_enable = 1")
result = tk.MustQuery("SELECT variable_value FROM mysql.tidb WHERE variable_name = 'tikv_gc_enable'")
result.Check(testkit.Rows("true"))

tk.MustExec("UPDATE mysql.tidb SET variable_value = 'false' WHERE variable_name='tikv_gc_enable'")
result = tk.MustQuery("SELECT @@tidb_gc_enable;")
result.Check(testkit.Rows("0")) // reads from mysql.tidb value and changes to false

tk.MustExec("SET GLOBAL tidb_gc_concurrency = -1") // sets auto concurrency and concurrency
result = tk.MustQuery("SELECT variable_value FROM mysql.tidb WHERE variable_name = 'tikv_gc_auto_concurrency'")
result.Check(testkit.Rows("true"))
result = tk.MustQuery("SELECT variable_value FROM mysql.tidb WHERE variable_name = 'tikv_gc_concurrency'")
result.Check(testkit.Rows("-1"))

tk.MustExec("SET GLOBAL tidb_gc_concurrency = 5") // sets auto concurrency and concurrency
result = tk.MustQuery("SELECT variable_value FROM mysql.tidb WHERE variable_name = 'tikv_gc_auto_concurrency'")
result.Check(testkit.Rows("false"))
result = tk.MustQuery("SELECT variable_value FROM mysql.tidb WHERE variable_name = 'tikv_gc_concurrency'")
result.Check(testkit.Rows("5"))

tk.MustExec("UPDATE mysql.tidb SET variable_value = 'true' WHERE variable_name='tikv_gc_auto_concurrency'")
result = tk.MustQuery("SELECT @@tidb_gc_concurrency;")
result.Check(testkit.Rows("-1")) // because auto_concurrency is turned on it takes precedence

tk.MustExec("REPLACE INTO mysql.tidb (variable_value, variable_name) VALUES ('15m', 'tikv_gc_run_interval')")
result = tk.MustQuery("SELECT @@GLOBAL.tidb_gc_run_interval;")
result.Check(testkit.Rows("15m0s"))
result = tk.MustQuery("SHOW GLOBAL VARIABLES LIKE 'tidb_gc_run_interval'")
result.Check(testkit.Rows("tidb_gc_run_interval 15m0s"))

tk.MustExec("SET GLOBAL tidb_gc_run_interval = '9m'") // too small
tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Truncated incorrect tidb_gc_run_interval value: '9m'"))
result = tk.MustQuery("SHOW GLOBAL VARIABLES LIKE 'tidb_gc_run_interval'")
result.Check(testkit.Rows("tidb_gc_run_interval 10m0s"))

tk.MustExec("SET GLOBAL tidb_gc_run_interval = '700000000000ns'") // specified in ns, also valid

_, err := tk.Exec("SET GLOBAL tidb_gc_run_interval = '11mins'")
require.Equal(t, "[variable:1232]Incorrect argument type to variable 'tidb_gc_run_interval'", err.Error())
}

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

Expand Down
7 changes: 0 additions & 7 deletions tests/integrationtest/r/executor/admin.result
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ create table cache_admin_test (c1 int, c2 int, c3 int default 1, index (c1), uni
insert cache_admin_test (c1, c2) values (1, 1), (2, 2), (5, 5), (10, 10), (11, 11);
alter table cache_admin_test cache;
admin check table cache_admin_test;

admin check index cache_admin_test c1;

admin check index cache_admin_test c2;

alter table cache_admin_test nocache;
drop table if exists cache_admin_test;
drop table if exists check_index_test;
Expand All @@ -69,11 +66,7 @@ create table cache_admin_table_without_index_test (id int, count int, PRIMARY KE
alter table cache_admin_table_with_index_test cache;
alter table cache_admin_table_without_index_test cache;
admin checksum table cache_admin_table_with_index_test;
Db_name Table_name Checksum_crc64_xor Total_kvs Total_bytes
executor__admin cache_admin_table_with_index_test 0 2 2
admin checksum table cache_admin_table_without_index_test;
Db_name Table_name Checksum_crc64_xor Total_kvs Total_bytes
executor__admin cache_admin_table_without_index_test 1 1 1
alter table cache_admin_table_with_index_test nocache;
alter table cache_admin_table_without_index_test nocache;
drop table if exists cache_admin_table_with_index_test,cache_admin_table_without_index_test;
Expand Down
4 changes: 0 additions & 4 deletions tests/integrationtest/r/executor/executor.result
Original file line number Diff line number Diff line change
Expand Up @@ -1258,10 +1258,6 @@ commit;
select a from t where id=1;
a
2
change pump to node_state ='paused' for node_id 'pump1';
Error 1105 (HY000): URL scheme must be http, https, unix, or unixs:
change drainer to node_state ='paused' for node_id 'drainer1';
Error 1105 (HY000): URL scheme must be http, https, unix, or unixs:
drop table if exists select_limit;
create table select_limit(id int not null default 1, name varchar(255), PRIMARY KEY(id));
insert INTO select_limit VALUES (1, "hello");
Expand Down
61 changes: 22 additions & 39 deletions tests/integrationtest/r/expression/builtin.result
Original file line number Diff line number Diff line change
Expand Up @@ -700,37 +700,27 @@ create table tb5(a double, b float);
insert into tb5 (a, b) values (184467440737095516160, 184467440737095516160);
select * from tb5 where cast(a as unsigned int)=0;
a b
Level Code Message
Warning 1690 constant 1.844674407370955e+20 overflows bigint
select * from tb5 where cast(b as unsigned int)=0;
a b
Level Code Message
Warning 1690 constant 1.844674407370955e+20 overflows bigint
drop table tb5;
create table tb5(a double, b bigint unsigned);
insert into tb5 (a, b) values (18446744073709551616, 18446744073709551615);
select * from tb5 where cast(a as unsigned int)=b;
a b
1.8446744073709552e19 18446744073709551615
Level Code Message
Warning 1690 constant 1.8446744073709552e+19 overflows bigint
drop table tb5;
create table tb5(a json, b bigint unsigned);
insert into tb5 (a, b) values ('184467440737095516160', 18446744073709551615);
select * from tb5 where cast(a as unsigned int)=b;
a b
184467440737095500000 18446744073709551615
Level Code Message
Warning 1690 constant 1.844674407370955e+20 overflows bigint
select * from tb5 where cast(b as unsigned int)=0;
a b
drop table tb5;
create table tb5(a json, b bigint unsigned);
insert into tb5 (a, b) values ('92233720368547758080', 18446744073709551615);
select * from tb5 where cast(a as signed int)=b;
a b
Level Code Message
Warning 1690 constant 9.223372036854776e+19 overflows bigint
drop table tb5;
create table tb5(a bigint(64) unsigned,b varchar(50));
insert into tb5(a, b) values (9223372036854775808, '9223372036854775808');
Expand Down Expand Up @@ -1893,20 +1883,18 @@ MySQL 123 123
select unhex('string'), unhex('你好'), unhex(123.4), unhex(null);
unhex('string') unhex('你好') unhex(123.4) unhex(null)
NULL NULL NULL NULL
select ltrim(' bar '), ltrim('bar'), ltrim(''), ltrim(null);
ltrim(' bar ') ltrim('bar') ltrim('') ltrim(null)
bar bar NULL
select rtrim(' bar '), rtrim('bar'), rtrim(''), rtrim(null);
rtrim(' bar ') rtrim('bar') rtrim('') rtrim(null)
bar bar NULL
select ltrim("\t bar "), ltrim(" \tbar"), ltrim("\n bar"), ltrim("\r bar");
ltrim("\t bar ") ltrim(" \tbar") ltrim("\n bar") ltrim("\r bar")
bar bar
bar bar
select rtrim(" bar \t"), rtrim("bar\t "), rtrim("bar \n"), rtrim("bar \r");
rtrim(" bar \t") rtrim("bar\t ") rtrim("bar \n") rtrim("bar \r")
bar bar bar
bar
select hex(ltrim(' bar ')), hex(ltrim('bar')), hex(ltrim('')), hex(ltrim(null));
hex(ltrim(' bar ')) hex(ltrim('bar')) hex(ltrim('')) hex(ltrim(null))
626172202020 626172 NULL
select hex(rtrim(' bar ')), hex(rtrim('bar')), hex(rtrim('')), hex(rtrim(null));
hex(rtrim(' bar ')) hex(rtrim('bar')) hex(rtrim('')) hex(rtrim(null))
202020626172 626172 NULL
select hex(ltrim("\t bar ")), hex(ltrim(" \tbar")), hex(ltrim("\n bar")), hex(ltrim("\r bar"));
hex(ltrim("\t bar ")) hex(ltrim(" \tbar")) hex(ltrim("\n bar")) hex(ltrim("\r bar"))
09202020626172202020 09626172 0A2020626172 0D2020626172
select hex(rtrim(" bar \t")), hex(rtrim("bar\t ")), hex(rtrim("bar \n")), hex(rtrim("bar \r"));
hex(rtrim(" bar \t")) hex(rtrim("bar\t ")) hex(rtrim("bar \n")) hex(rtrim("bar \r"))
20202062617220202009 62617209 6261722020200A 6261722020200D
DROP TABLE IF EXISTS t;
CREATE TABLE t(a BINARY(6));
INSERT INTO t VALUES("中文");
Expand All @@ -1919,18 +1907,17 @@ hex(REVERSE(123)) hex(REVERSE(12.09))
select trim(' bar '), trim(leading 'x' from 'xxxbarxxx'), trim(trailing 'xyz' from 'barxxyz'), trim(both 'x' from 'xxxbarxxx');
trim(' bar ') trim(leading 'x' from 'xxxbarxxx') trim(trailing 'xyz' from 'barxxyz') trim(both 'x' from 'xxxbarxxx')
bar barxxx barx bar
select trim('\t bar\n '), trim(' \rbar \t');
trim('\t bar\n ') trim(' \rbar \t')
bar
bar
select trim(leading from ' bar'), trim('x' from 'xxxbarxxx'), trim('x' from 'bar'), trim('' from ' bar ');
trim(leading from ' bar') trim('x' from 'xxxbarxxx') trim('x' from 'bar') trim('' from ' bar ')
bar bar bar bar
select trim(''), trim('x' from '');
trim('') trim('x' from '')
select hex(trim('\t bar\n ')), hex(trim(' \rbar \t'));
hex(trim('\t bar\n ')) hex(trim(' \rbar \t'))
092020206261720A 0D62617220202009
select hex(trim(leading from ' bar')), hex(trim('x' from 'xxxbarxxx')), hex(trim('x' from 'bar')), hex(trim('' from ' bar '));
hex(trim(leading from ' bar')) hex(trim('x' from 'xxxbarxxx')) hex(trim('x' from 'bar')) hex(trim('' from ' bar '))
626172 626172 626172 202020626172202020
select hex(trim('')), hex(trim('x' from ''));
hex(trim('')) hex(trim('x' from ''))

select trim(null from 'bar'), trim('x' from null), trim(null), trim(leading null from 'bar');
trim(null from 'bar') trim('x' from null) trim(null) trim(leading null from 'bar')
select hex(trim(null from 'bar')), hex(trim('x' from null)), hex(trim(null)), hex(trim(leading null from 'bar'));
hex(trim(null from 'bar')) hex(trim('x' from null)) hex(trim(null)) hex(trim(leading null from 'bar'))
NULL NULL NULL NULL
drop table if exists t;
create table t(a char(20), b int, c double, d datetime, e time, f binary(5));
Expand Down Expand Up @@ -2328,8 +2315,6 @@ select cast(12 as signed) - cast(-9223372036854775808 as signed);
Error 1690 (22003): BIGINT value is out of range in '(12 - -9223372036854775808)'
create table tb5(a int(10));
insert into tb5 (a) values (10);
select * from tb5 where a - -9223372036854775808;
Error 1690 (22003): BIGINT value is out of range in '(Column#0 - -9223372036854775808)'
drop table tb5;
select cast(-9223372036854775808 as unsigned) - (-9223372036854775807);
cast(-9223372036854775808 as unsigned) - (-9223372036854775807)
Expand Down Expand Up @@ -2468,8 +2453,6 @@ create table t(a double);
insert into t value(1.2);
select * from t where a/0 > 1;
a
Level Code Message
Warning 1365 Division by 0
DROP TABLE IF EXISTS t;
CREATE TABLE t(a BIGINT, b DECIMAL(6, 2));
INSERT INTO t VALUES(0, 1.12), (1, 1.21);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,6 @@ a b c d e f g h i
1 啊 啊 啊 啊 啊 啊 🐸 🐸
admin check table t;

admin recover index t a;
ADDED_COUNT SCAN_COUNT
0 1
alter table t add column n char(10) COLLATE utf8mb4_unicode_ci;
alter table t add index n(n);
update t set n = '吧';
Expand Down
18 changes: 0 additions & 18 deletions tests/integrationtest/r/expression/issues.result
Original file line number Diff line number Diff line change
Expand Up @@ -2169,18 +2169,6 @@ a A a A
select * from t t1 left join t t2 on t1.a = t2.b collate utf8mb4_general_ci;
a b a b
a A a A
drop table if exists t;
create table t(a varchar(10) collate utf8mb4_bin, b varchar(10) collate utf8mb4_general_ci);
insert into t (a, b) values ('a', 'A');
select * from t where field('A', a collate utf8mb4_general_ci, b) > 1;
a b
select * from t where field('A', a, b collate utf8mb4_general_ci) > 1;
a b
select * from t where field('A' collate utf8mb4_general_ci, a, b) > 1;
a b
select * from t where field('A', a, b) > 1;
a b
a A
set names utf8mb4 collate utf8mb4_general_ci;
select collation(concat(1 collate `binary`));
collation(concat(1 collate `binary`))
Expand Down Expand Up @@ -2763,15 +2751,9 @@ insert into t values('1e649'),('-1e649');
SELECT * FROM t where c < 1;
c
-1e649
Level Code Message
Warning 1292 Truncated incorrect DOUBLE value: '-1e649'
Warning 1292 Truncated incorrect DOUBLE value: '1e649'
SELECT * FROM t where c > 1;
c
1e649
Level Code Message
Warning 1292 Truncated incorrect DOUBLE value: '-1e649'
Warning 1292 Truncated incorrect DOUBLE value: '1e649'
drop table if exists t;
create table t(a int);
insert t values (1);
Expand Down
23 changes: 2 additions & 21 deletions tests/integrationtest/r/planner/core/plan_cache.result
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ col1
471841432147994.4981
492790234219503.0846
729024465529090.5423
create database test_40296;
use test_40296;
drop table if exists IDT_MULTI15880STROBJSTROBJ;
CREATE TABLE IDT_MULTI15880STROBJSTROBJ (
COL1 enum('aa','bb','cc','dd','ff','gg','kk','ll','mm','ee') DEFAULT NULL,
COL2 decimal(20,0) DEFAULT NULL,
Expand All @@ -275,7 +274,7 @@ ee -9605492323393070105 0850-03-15
select @@last_plan_from_cache;
@@last_plan_from_cache
0
use planner__core__plan_cache
set session tidb_enable_non_prepared_plan_cache=default;
CREATE TABLE UK_SIGNED_19385 (
COL1 decimal(37,4) unsigned DEFAULT '101.0000' COMMENT 'WITH DEFAULT',
COL2 varchar(20) DEFAULT NULL,
Expand All @@ -288,24 +287,6 @@ select * from UK_SIGNED_19385 where col1 = 999999999999999999999999999999999.999
col1 * 999999999999999999999999999999999.9999 between 999999999999999999999999999999999.9999 and
999999999999999999999999999999999.9999;
COL1 COL2 COL4 COL3 COL5
CREATE TABLE IDT_20290 (
COL1 mediumtext DEFAULT NULL,
COL2 decimal(52,7) DEFAULT NULL,
COL3 datetime DEFAULT NULL,
KEY U_M_COL (COL1(10),COL2,COL3) /*!80000 INVISIBLE */);
INSERT INTO IDT_20290 VALUES
('',210255309400.4264137,'4273-04-17 17:26:51'),
(NULL,952470120213.2538798,'7087-08-19 21:38:49'),
('俦',486763966102.1656494,'8846-06-12 12:02:13'),
('憁',610644171405.5953911,'2529-07-19 17:24:49'),
('顜',-359717183823.5275069,'2599-04-01 00:12:08'),
('塼',466512908211.1135111,'1477-10-20 07:14:51'),
('宻',-564216096745.0427987,'7071-11-20 13:38:24'),
('網',-483373421083.4724254,'2910-02-19 18:29:17'),
('顥',164020607693.9988781,'2820-10-12 17:38:44'),
('谪',25949740494.3937876,'6527-05-30 22:58:37');
select * from IDT_20290 where col2 * 049015787697063065230692384394107598316198958.1850509 >= 659971401668884663953087553591534913868320924.5040396 and col2 = 869042976700631943559871054704914143535627349.9659934;
Error 1690 (22003): DECIMAL value is out of range in '(869042976700631943559871054704914143535627349.9659934 * 49015787697063065230692384394107598316198958.1850509)'
drop table if exists t;
create table t(a varchar(8) not null, b varchar(8) not null);
insert into t values('1','1');
Expand Down
50 changes: 0 additions & 50 deletions tests/integrationtest/r/session/vars.result
Original file line number Diff line number Diff line change
@@ -1,53 +1,3 @@
SHOW GLOBAL VARIABLES LIKE 'tidb_gc_enable';
Variable_name Value
tidb_gc_enable ON
SELECT variable_value FROM mysql.tidb WHERE variable_name = 'tikv_gc_enable';
variable_value
SET GLOBAL tidb_gc_enable = 1;
SELECT variable_value FROM mysql.tidb WHERE variable_name = 'tikv_gc_enable';
variable_value
true
UPDATE mysql.tidb SET variable_value = 'false' WHERE variable_name='tikv_gc_enable';
SELECT @@tidb_gc_enable;
@@tidb_gc_enable
0
SET GLOBAL tidb_gc_concurrency = -1;
SELECT variable_value FROM mysql.tidb WHERE variable_name = 'tikv_gc_auto_concurrency';
variable_value
true
SELECT variable_value FROM mysql.tidb WHERE variable_name = 'tikv_gc_concurrency';
variable_value
-1
SET GLOBAL tidb_gc_concurrency = 5;
SELECT variable_value FROM mysql.tidb WHERE variable_name = 'tikv_gc_auto_concurrency';
variable_value
false
SELECT variable_value FROM mysql.tidb WHERE variable_name = 'tikv_gc_concurrency';
variable_value
5
UPDATE mysql.tidb SET variable_value = 'true' WHERE variable_name='tikv_gc_auto_concurrency';
SELECT @@tidb_gc_concurrency;
@@tidb_gc_concurrency
-1
REPLACE INTO mysql.tidb (variable_value, variable_name) VALUES ('15m', 'tikv_gc_run_interval');
SELECT @@GLOBAL.tidb_gc_run_interval;
@@GLOBAL.tidb_gc_run_interval
15m0s
SHOW GLOBAL VARIABLES LIKE 'tidb_gc_run_interval';
Variable_name Value
tidb_gc_run_interval 15m0s
SET GLOBAL tidb_gc_run_interval = '9m';
Level Code Message
Warning 1292 Truncated incorrect tidb_gc_run_interval value: '9m'
SHOW GLOBAL VARIABLES LIKE 'tidb_gc_run_interval';
Variable_name Value
tidb_gc_run_interval 10m0s
SET GLOBAL tidb_gc_run_interval = '700000000000ns';
SET GLOBAL tidb_gc_run_interval = '11mins';
Error 1232 (42000): Incorrect argument type to variable 'tidb_gc_run_interval'
set global tidb_gc_run_interval = default;
set global tidb_gc_concurrency = default;
SET GLOBAL tidb_gc_enable = default;
set tidb_enable_legacy_instance_scope = 1;
set tidb_general_log = 1;
Level Code Message
Expand Down
Loading

0 comments on commit e542b87

Please sign in to comment.