diff --git a/planner/core/casetest/BUILD.bazel b/planner/core/casetest/BUILD.bazel index 9033906b0f1eb..b3b99e1384d03 100644 --- a/planner/core/casetest/BUILD.bazel +++ b/planner/core/casetest/BUILD.bazel @@ -5,16 +5,13 @@ go_test( timeout = "moderate", srcs = [ "expression_rewriter_test.go", - "integration_partition_test.go", "integration_test.go", "main_test.go", - "partition_pruner_test.go", "plan_test.go", "point_get_plan_test.go", "predicate_simplification_test.go", "stats_test.go", "tiflash_selection_late_materialization_test.go", - "window_push_down_test.go", ], data = glob(["testdata/**"]), flaky = True, diff --git a/planner/core/casetest/main_test.go b/planner/core/casetest/main_test.go index 689904faeaa89..fe878c3b62311 100644 --- a/planner/core/casetest/main_test.go +++ b/planner/core/casetest/main_test.go @@ -30,19 +30,12 @@ func TestMain(m *testing.M) { testsetup.SetupForCommonTest() flag.Parse() - - testDataMap.LoadTestSuiteData("testdata", "integration_partition_suite") testDataMap.LoadTestSuiteData("testdata", "plan_normalized_suite") testDataMap.LoadTestSuiteData("testdata", "stats_suite") - testDataMap.LoadTestSuiteData("testdata", "point_get_plan") testDataMap.LoadTestSuiteData("testdata", "expression_rewriter_suite") - testDataMap.LoadTestSuiteData("testdata", "partition_pruner") testDataMap.LoadTestSuiteData("testdata", "integration_suite") - testDataMap.LoadTestSuiteData("testdata", "window_push_down_suite") - testDataMap.LoadTestSuiteData("testdata", "json_plan_suite") - testDataMap.LoadTestSuiteData("testdata", "predicate_simplification") opts := []goleak.Option{ @@ -62,10 +55,6 @@ func TestMain(m *testing.M) { goleak.VerifyTestMain(testmain.WrapTestingM(m, callback), opts...) } -func GetIntegrationPartitionSuiteData() testdata.TestData { - return testDataMap["integration_partition_suite"] -} - func GetPlanNormalizedSuiteData() testdata.TestData { return testDataMap["plan_normalized_suite"] } @@ -82,18 +71,10 @@ func GetExpressionRewriterSuiteData() testdata.TestData { return testDataMap["expression_rewriter_suite"] } -func GetPartitionPrunerData() testdata.TestData { - return testDataMap["partition_pruner"] -} - func GetIntegrationSuiteData() testdata.TestData { return testDataMap["integration_suite"] } -func GetWindowPushDownSuiteData() testdata.TestData { - return testDataMap["window_push_down_suite"] -} - func GetJSONPlanSuiteData() testdata.TestData { return testDataMap["json_plan_suite"] } diff --git a/planner/core/casetest/partition/BUILD.bazel b/planner/core/casetest/partition/BUILD.bazel new file mode 100644 index 0000000000000..5fc3ce94d3232 --- /dev/null +++ b/planner/core/casetest/partition/BUILD.bazel @@ -0,0 +1,25 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_test") + +go_test( + name = "partition_test", + timeout = "short", + srcs = [ + "integration_partition_test.go", + "main_test.go", + "partition_pruner_test.go", + ], + data = glob(["testdata/**"]), + flaky = True, + shard_count = 10, + deps = [ + "//planner/core/internal", + "//sessionctx/variable", + "//testkit", + "//testkit/testdata", + "//testkit/testmain", + "//testkit/testsetup", + "@com_github_pingcap_failpoint//:failpoint", + "@com_github_stretchr_testify//require", + "@org_uber_go_goleak//:goleak", + ], +) diff --git a/planner/core/casetest/integration_partition_test.go b/planner/core/casetest/partition/integration_partition_test.go similarity index 95% rename from planner/core/casetest/integration_partition_test.go rename to planner/core/casetest/partition/integration_partition_test.go index 182553717facd..4e6bd14172961 100644 --- a/planner/core/casetest/integration_partition_test.go +++ b/planner/core/casetest/partition/integration_partition_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package casetest +package partition import ( "strings" @@ -45,7 +45,7 @@ func TestListPartitionPushDown(t *testing.T) { SQL string Plan []string } - integrationPartitionSuiteData := GetIntegrationPartitionSuiteData() + integrationPartitionSuiteData := getIntegrationPartitionSuiteData() integrationPartitionSuiteData.LoadTestCases(t, &input, &output) for i, tt := range input { testdata.OnRecord(func() { @@ -89,7 +89,7 @@ func TestListColVariousTypes(t *testing.T) { SQL string Results []string } - integrationPartitionSuiteData := GetIntegrationPartitionSuiteData() + integrationPartitionSuiteData := getIntegrationPartitionSuiteData() integrationPartitionSuiteData.LoadTestCases(t, &input, &output) for i, tt := range input { testdata.OnRecord(func() { @@ -130,7 +130,7 @@ func TestListPartitionPruning(t *testing.T) { DynamicPlan []string StaticPlan []string } - integrationPartitionSuiteData := GetIntegrationPartitionSuiteData() + integrationPartitionSuiteData := getIntegrationPartitionSuiteData() integrationPartitionSuiteData.LoadTestCases(t, &input, &output) for i, tt := range input { testdata.OnRecord(func() { @@ -161,7 +161,7 @@ func TestListPartitionFunctions(t *testing.T) { SQL string Results []string } - integrationPartitionSuiteData := GetIntegrationPartitionSuiteData() + integrationPartitionSuiteData := getIntegrationPartitionSuiteData() integrationPartitionSuiteData.LoadTestCases(t, &input, &output) for i, tt := range input { testdata.OnRecord(func() { @@ -209,7 +209,7 @@ func TestEstimationForTopNPushToDynamicPartition(t *testing.T) { SQL string Plan []string } - integrationPartitionSuiteData := GetIntegrationPartitionSuiteData() + integrationPartitionSuiteData := getIntegrationPartitionSuiteData() integrationPartitionSuiteData.LoadTestCases(t, &input, &output) for i, tt := range input { testdata.OnRecord(func() { diff --git a/planner/core/casetest/partition/main_test.go b/planner/core/casetest/partition/main_test.go new file mode 100644 index 0000000000000..b12f2393d7f16 --- /dev/null +++ b/planner/core/casetest/partition/main_test.go @@ -0,0 +1,57 @@ +// Copyright 2023 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package partition + +import ( + "flag" + "testing" + + "github.com/pingcap/tidb/testkit/testdata" + "github.com/pingcap/tidb/testkit/testmain" + "github.com/pingcap/tidb/testkit/testsetup" + "go.uber.org/goleak" +) + +var testDataMap = make(testdata.BookKeeper) + +func TestMain(m *testing.M) { + testsetup.SetupForCommonTest() + flag.Parse() + testDataMap.LoadTestSuiteData("testdata", "integration_partition_suite") + testDataMap.LoadTestSuiteData("testdata", "partition_pruner") + opts := []goleak.Option{ + goleak.IgnoreTopFunction("github.com/golang/glog.(*fileSink).flushDaemon"), + goleak.IgnoreTopFunction("github.com/lestrrat-go/httprc.runFetchWorker"), + goleak.IgnoreTopFunction("go.etcd.io/etcd/client/pkg/v3/logutil.(*MergeLogger).outputLoop"), + goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).millRun"), + goleak.IgnoreTopFunction("github.com/tikv/client-go/v2/txnkv/transaction.keepAlive"), + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + } + + callback := func(i int) int { + testDataMap.GenerateOutputIfNeeded() + return i + } + + goleak.VerifyTestMain(testmain.WrapTestingM(m, callback), opts...) +} + +func getIntegrationPartitionSuiteData() testdata.TestData { + return testDataMap["integration_partition_suite"] +} + +func getPartitionPrunerData() testdata.TestData { + return testDataMap["partition_pruner"] +} diff --git a/planner/core/casetest/partition_pruner_test.go b/planner/core/casetest/partition/partition_pruner_test.go similarity index 98% rename from planner/core/casetest/partition_pruner_test.go rename to planner/core/casetest/partition/partition_pruner_test.go index fb0140de06750..4d5fad6939dba 100644 --- a/planner/core/casetest/partition_pruner_test.go +++ b/planner/core/casetest/partition/partition_pruner_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package casetest +package partition import ( "bytes" @@ -54,7 +54,7 @@ func TestHashPartitionPruner(t *testing.T) { SQL string Result []string } - partitionPrunerData := GetPartitionPrunerData() + partitionPrunerData := getPartitionPrunerData() partitionPrunerData.LoadTestCases(t, &input, &output) for i, tt := range input { testdata.OnRecord(func() { @@ -118,7 +118,7 @@ func TestListPartitionPruner(t *testing.T) { Result []string Plan []string } - partitionPrunerData := GetPartitionPrunerData() + partitionPrunerData := getPartitionPrunerData() partitionPrunerData.LoadTestCases(t, &input, &output) valid := false for i, tt := range input { @@ -247,7 +247,7 @@ func TestListColumnsPartitionPruner(t *testing.T) { Plan []string IndexPlan []string } - partitionPrunerData := GetPartitionPrunerData() + partitionPrunerData := getPartitionPrunerData() partitionPrunerData.LoadTestCases(t, &input, &output) valid := false for i, tt := range input { @@ -310,7 +310,7 @@ func TestRangePartitionPredicatePruner(t *testing.T) { SQL string Result []string } - partitionPrunerData := GetPartitionPrunerData() + partitionPrunerData := getPartitionPrunerData() partitionPrunerData.LoadTestCases(t, &input, &output) for i, tt := range input { testdata.OnRecord(func() { diff --git a/planner/core/casetest/testdata/integration_partition_suite_in.json b/planner/core/casetest/partition/testdata/integration_partition_suite_in.json similarity index 100% rename from planner/core/casetest/testdata/integration_partition_suite_in.json rename to planner/core/casetest/partition/testdata/integration_partition_suite_in.json diff --git a/planner/core/casetest/testdata/integration_partition_suite_out.json b/planner/core/casetest/partition/testdata/integration_partition_suite_out.json similarity index 100% rename from planner/core/casetest/testdata/integration_partition_suite_out.json rename to planner/core/casetest/partition/testdata/integration_partition_suite_out.json diff --git a/planner/core/casetest/testdata/partition_pruner_in.json b/planner/core/casetest/partition/testdata/partition_pruner_in.json similarity index 100% rename from planner/core/casetest/testdata/partition_pruner_in.json rename to planner/core/casetest/partition/testdata/partition_pruner_in.json diff --git a/planner/core/casetest/testdata/partition_pruner_out.json b/planner/core/casetest/partition/testdata/partition_pruner_out.json similarity index 100% rename from planner/core/casetest/testdata/partition_pruner_out.json rename to planner/core/casetest/partition/testdata/partition_pruner_out.json diff --git a/planner/core/casetest/predicate_simplification_test.go b/planner/core/casetest/predicate_simplification_test.go index 67bf03d079de6..39638d5b900b6 100644 --- a/planner/core/casetest/predicate_simplification_test.go +++ b/planner/core/casetest/predicate_simplification_test.go @@ -21,6 +21,8 @@ import ( "github.com/pingcap/tidb/testkit/testdata" ) +type Input []string + func TestRemoveRedundantPredicates(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) diff --git a/planner/core/casetest/windows/BUILD.bazel b/planner/core/casetest/windows/BUILD.bazel new file mode 100644 index 0000000000000..54eece02b22cb --- /dev/null +++ b/planner/core/casetest/windows/BUILD.bazel @@ -0,0 +1,24 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_test") + +go_test( + name = "windows_test", + timeout = "short", + srcs = [ + "main_test.go", + "window_push_down_test.go", + ], + data = glob(["testdata/**"]), + flaky = True, + shard_count = 4, + deps = [ + "//domain", + "//planner/core/internal", + "//testkit", + "//testkit/testdata", + "//testkit/testmain", + "//testkit/testsetup", + "@com_github_pingcap_failpoint//:failpoint", + "@com_github_stretchr_testify//require", + "@org_uber_go_goleak//:goleak", + ], +) diff --git a/planner/core/casetest/windows/main_test.go b/planner/core/casetest/windows/main_test.go new file mode 100644 index 0000000000000..71e2336422a0e --- /dev/null +++ b/planner/core/casetest/windows/main_test.go @@ -0,0 +1,52 @@ +// Copyright 2023 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package windows + +import ( + "flag" + "testing" + + "github.com/pingcap/tidb/testkit/testdata" + "github.com/pingcap/tidb/testkit/testmain" + "github.com/pingcap/tidb/testkit/testsetup" + "go.uber.org/goleak" +) + +var testDataMap = make(testdata.BookKeeper) + +func TestMain(m *testing.M) { + testsetup.SetupForCommonTest() + flag.Parse() + testDataMap.LoadTestSuiteData("testdata", "window_push_down_suite") + opts := []goleak.Option{ + goleak.IgnoreTopFunction("github.com/golang/glog.(*fileSink).flushDaemon"), + goleak.IgnoreTopFunction("github.com/lestrrat-go/httprc.runFetchWorker"), + goleak.IgnoreTopFunction("go.etcd.io/etcd/client/pkg/v3/logutil.(*MergeLogger).outputLoop"), + goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).millRun"), + goleak.IgnoreTopFunction("github.com/tikv/client-go/v2/txnkv/transaction.keepAlive"), + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + } + + callback := func(i int) int { + testDataMap.GenerateOutputIfNeeded() + return i + } + + goleak.VerifyTestMain(testmain.WrapTestingM(m, callback), opts...) +} + +func getWindowPushDownSuiteData() testdata.TestData { + return testDataMap["window_push_down_suite"] +} diff --git a/planner/core/casetest/testdata/window_push_down_suite_in.json b/planner/core/casetest/windows/testdata/window_push_down_suite_in.json similarity index 100% rename from planner/core/casetest/testdata/window_push_down_suite_in.json rename to planner/core/casetest/windows/testdata/window_push_down_suite_in.json diff --git a/planner/core/casetest/testdata/window_push_down_suite_out.json b/planner/core/casetest/windows/testdata/window_push_down_suite_out.json similarity index 100% rename from planner/core/casetest/testdata/window_push_down_suite_out.json rename to planner/core/casetest/windows/testdata/window_push_down_suite_out.json diff --git a/planner/core/casetest/window_push_down_test.go b/planner/core/casetest/windows/window_push_down_test.go similarity index 96% rename from planner/core/casetest/window_push_down_test.go rename to planner/core/casetest/windows/window_push_down_test.go index 7e3f08845b6ed..05f0a4d0a1652 100644 --- a/planner/core/casetest/window_push_down_test.go +++ b/planner/core/casetest/windows/window_push_down_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package casetest +package windows import ( "strings" @@ -67,7 +67,7 @@ func TestWindowFunctionDescCanPushDown(t *testing.T) { var input Input var output Output - suiteData := GetWindowPushDownSuiteData() + suiteData := getWindowPushDownSuiteData() suiteData.LoadTestCases(t, &input, &output) testWithData(t, tk, input, output) } @@ -84,7 +84,7 @@ func TestWindowPushDownPlans(t *testing.T) { var input Input var output Output - suiteData := GetWindowPushDownSuiteData() + suiteData := getWindowPushDownSuiteData() suiteData.LoadTestCases(t, &input, &output) testWithData(t, tk, input, output) } @@ -102,7 +102,7 @@ func TestWindowPlanWithOtherOperators(t *testing.T) { var input Input var output Output - suiteData := GetWindowPushDownSuiteData() + suiteData := getWindowPushDownSuiteData() suiteData.LoadTestCases(t, &input, &output) testWithData(t, tk, input, output) }