From 04cb38febf31bab3631a2de0c11b33a6b667e454 Mon Sep 17 00:00:00 2001 From: Yiding Date: Fri, 20 Sep 2024 00:39:39 +0800 Subject: [PATCH 1/4] tests: reduce some flaky timeout tests --- .../test/clustertablestest/cluster_tables_test.go | 8 +++++++- pkg/server/handler/tests/http_handler_serial_test.go | 3 +-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/infoschema/test/clustertablestest/cluster_tables_test.go b/pkg/infoschema/test/clustertablestest/cluster_tables_test.go index ca2fefc95a083..d77bcc644feb9 100644 --- a/pkg/infoschema/test/clustertablestest/cluster_tables_test.go +++ b/pkg/infoschema/test/clustertablestest/cluster_tables_test.go @@ -911,7 +911,7 @@ func TestMDLView(t *testing.T) { } } -func TestMDLViewPrivilege(t *testing.T) { +func TestMDLViewPrivilege1(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)) @@ -921,8 +921,14 @@ func TestMDLViewPrivilege(t *testing.T) { _, err := tk.Exec("select * from mysql.tidb_mdl_view;") require.ErrorContains(t, err, "view lack rights") +} + +func TestMDLViewPrivilege2(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) // grant all privileges to test user. require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) + tk.MustExec("create user 'test'@'%' identified by '';") tk.MustExec("grant all privileges on *.* to 'test'@'%';") tk.MustExec("flush privileges;") require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "test", Hostname: "%"}, nil, nil, nil)) diff --git a/pkg/server/handler/tests/http_handler_serial_test.go b/pkg/server/handler/tests/http_handler_serial_test.go index 6ba324dc2a38f..f9e9a6b3e30b8 100644 --- a/pkg/server/handler/tests/http_handler_serial_test.go +++ b/pkg/server/handler/tests/http_handler_serial_test.go @@ -454,11 +454,10 @@ func TestDebugRoutes(t *testing.T) { "/debug/pprof/block?debug=1", "/debug/pprof/threadcreate?debug=1", "/debug/pprof/cmdline", - "/debug/pprof/profile", + "/debug/pprof/profile?seconds=5", "/debug/pprof/mutex?debug=1", "/debug/pprof/symbol", "/debug/pprof/trace", - "/debug/pprof/profile", "/debug/gogc", // "/debug/zip", // this creates unexpected goroutines which will make goleak complain, so we skip it for now "/debug/ballast-object-sz", From a30c50eb92898797f62cf352fee2002e9fb1c248 Mon Sep 17 00:00:00 2001 From: Yiding Date: Fri, 20 Sep 2024 02:31:08 +0800 Subject: [PATCH 2/4] add two more --- pkg/executor/test/cte/cte_test.go | 12 ++++++++---- .../core/memtable_infoschema_extractor_test.go | 14 +++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/pkg/executor/test/cte/cte_test.go b/pkg/executor/test/cte/cte_test.go index 1bebfa025e5e6..513c978c49eb3 100644 --- a/pkg/executor/test/cte/cte_test.go +++ b/pkg/executor/test/cte/cte_test.go @@ -167,11 +167,15 @@ func TestCTEDelSpillFile(t *testing.T) { tk.MustExec("drop table if exists t1, t2;") tk.MustExec("create table t1(c1 int, c2 int);") tk.MustExec("create table t2(c1 int);") - tk.MustExec("set @@cte_max_recursion_depth = 1000000;") - tk.MustExec("set global tidb_mem_oom_action = 'log';") - tk.MustExec("set @@tidb_mem_quota_query = 100;") tk.MustExec("insert into t2 values(1);") - tk.MustExec("insert into t1 (c1, c2) with recursive cte1 as (select c1 from t2 union select cte1.c1 + 1 from cte1 where cte1.c1 < 100000) select cte1.c1, cte1.c1+1 from cte1;") + tk.MustExec("set @@cte_max_recursion_depth = 100;") + tk.MustExec("set @@tidb_mem_quota_query = 100;") + tk.MustExec("set global tidb_mem_oom_action = 'cancel';") + // Make sure the OOM happens. + tk.MustExecToErr("insert into t1 (c1, c2) with recursive cte1 as (select c1 from t2 union select cte1.c1 + 1 from cte1 where cte1.c1 < 100) select cte1.c1, cte1.c1+1 from cte1;") + tk.MustExec("set global tidb_mem_oom_action = 'log';") + // Test that the storage is cleaned as expected. + tk.MustExec("insert into t1 (c1, c2) with recursive cte1 as (select c1 from t2 union select cte1.c1 + 1 from cte1 where cte1.c1 < 100) select cte1.c1, cte1.c1+1 from cte1;") require.Nil(t, tk.Session().GetSessionVars().StmtCtx.CTEStorageMap) } diff --git a/pkg/planner/core/memtable_infoschema_extractor_test.go b/pkg/planner/core/memtable_infoschema_extractor_test.go index bcc61d1e688c8..cf429e7495c92 100644 --- a/pkg/planner/core/memtable_infoschema_extractor_test.go +++ b/pkg/planner/core/memtable_infoschema_extractor_test.go @@ -390,6 +390,12 @@ func TestMemtableInfoschemaExtractorPart1(t *testing.T) { prepareData: prepareDataViews, cleanData: cleanDataViews, }, + } + testMemtableInfoschemaExtractor(t, tcs) +} + +func TestMemtableInfoschemaExtractorPart2(t *testing.T) { + tcs := []testCase{ { memTableName: infoschema.TableKeyColumn, prepareData: prepareDataKeyColumnUsage, @@ -409,7 +415,7 @@ func TestMemtableInfoschemaExtractorPart1(t *testing.T) { testMemtableInfoschemaExtractor(t, tcs) } -func TestMemtableInfoschemaExtractorPart2(t *testing.T) { +func TestMemtableInfoschemaExtractorPart3(t *testing.T) { tcs := []testCase{ { memTableName: infoschema.TableStatistics, @@ -426,6 +432,12 @@ func TestMemtableInfoschemaExtractorPart2(t *testing.T) { prepareData: prepareDataCheckConstraints, cleanData: cleanDataCheckConstraints, }, + } + testMemtableInfoschemaExtractor(t, tcs) +} + +func TestMemtableInfoschemaExtractorPart4(t *testing.T) { + tcs := []testCase{ { memTableName: infoschema.TableTiDBCheckConstraints, prepareData: prepareDataTidbCheckConstraints, From 1b410300618a0258531e0d81df136e0fbb3408b1 Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Fri, 20 Sep 2024 03:04:51 +0800 Subject: [PATCH 3/4] Update cluster_tables_test.go --- .../test/clustertablestest/cluster_tables_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/infoschema/test/clustertablestest/cluster_tables_test.go b/pkg/infoschema/test/clustertablestest/cluster_tables_test.go index d77bcc644feb9..cda6e486bd487 100644 --- a/pkg/infoschema/test/clustertablestest/cluster_tables_test.go +++ b/pkg/infoschema/test/clustertablestest/cluster_tables_test.go @@ -911,7 +911,8 @@ func TestMDLView(t *testing.T) { } } -func TestMDLViewPrivilege1(t *testing.T) { +func TestMDLViewWithNoPrivilege(t *testing.T) { + // It's with TestMDLViewWithPrivilege. Split to two tests just because it runs too much time. store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) @@ -920,10 +921,9 @@ func TestMDLViewPrivilege1(t *testing.T) { require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "test", Hostname: "%"}, nil, nil, nil)) _, err := tk.Exec("select * from mysql.tidb_mdl_view;") require.ErrorContains(t, err, "view lack rights") - } -func TestMDLViewPrivilege2(t *testing.T) { +func TestMDLViewWithPrivilege(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) // grant all privileges to test user. From 0d16da1e2bb53b7a2e9f129631d9bf4d78e52892 Mon Sep 17 00:00:00 2001 From: Yiding Date: Fri, 20 Sep 2024 04:33:23 +0800 Subject: [PATCH 4/4] add one more --- pkg/planner/core/plan_cost_ver1_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/planner/core/plan_cost_ver1_test.go b/pkg/planner/core/plan_cost_ver1_test.go index 5320c0e618091..496a916e1f963 100644 --- a/pkg/planner/core/plan_cost_ver1_test.go +++ b/pkg/planner/core/plan_cost_ver1_test.go @@ -103,7 +103,7 @@ func TestScanOnSmallTable(t *testing.T) { tk.MustExec("use test") tk.MustExec(`create table t (a int)`) tk.MustExec("insert into t values (1), (2), (3), (4), (5)") - tk.MustExec("analyze table t") + tk.MustExec("analyze table t all columns") tk.MustExec(`set @@tidb_cost_model_version=2`) // Create virtual tiflash replica info.