Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

casetest: split test for improving ci #45341

Merged
merged 3 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions planner/core/casetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 0 additions & 19 deletions planner/core/casetest/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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"]
}
Expand All @@ -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"]
}
Expand Down
25 changes: 25 additions & 0 deletions planner/core/casetest/partition/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package casetest
package partition

import (
"strings"
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
57 changes: 57 additions & 0 deletions planner/core/casetest/partition/main_test.go
Original file line number Diff line number Diff line change
@@ -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"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package casetest
package partition

import (
"bytes"
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions planner/core/casetest/predicate_simplification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions planner/core/casetest/windows/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
52 changes: 52 additions & 0 deletions planner/core/casetest/windows/main_test.go
Original file line number Diff line number Diff line change
@@ -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"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package casetest
package windows

import (
"strings"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down