Skip to content

Commit

Permalink
planner: move some test into tests package (#56353)
Browse files Browse the repository at this point in the history
close #56352
  • Loading branch information
hawkingrei authored Sep 27, 2024
1 parent f2ed822 commit 73f1cfe
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 14 deletions.
1 change: 0 additions & 1 deletion pkg/executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ go_test(
"executor_pkg_test.go",
"executor_required_rows_test.go",
"executor_test.go",
"executor_txn_test.go",
"explain_test.go",
"explain_unit_test.go",
"explainfor_test.go",
Expand Down
23 changes: 23 additions & 0 deletions pkg/executor/test/txn/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "txn_test",
timeout = "short",
srcs = [
"main_test.go",
"txn_test.go",
],
flaky = True,
shard_count = 9,
deps = [
"//pkg/config",
"//pkg/errno",
"//pkg/meta/autoid",
"//pkg/testkit",
"//pkg/testkit/testfailpoint",
"@com_github_stretchr_testify//require",
"@com_github_tikv_client_go_v2//tikv",
"@io_opencensus_go//stats/view",
"@org_uber_go_goleak//:goleak",
],
)
50 changes: 50 additions & 0 deletions pkg/executor/test/txn/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2024 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 txn

import (
"testing"

"github.com/pingcap/tidb/pkg/config"
"github.com/pingcap/tidb/pkg/meta/autoid"
"github.com/tikv/client-go/v2/tikv"
"go.opencensus.io/stats/view"
"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
autoid.SetStep(5000)
config.UpdateGlobal(func(conf *config.Config) {
conf.Log.SlowThreshold = 30000 // 30s
conf.TiKVClient.AsyncCommit.SafeWindow = 0
conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0
conf.Experimental.AllowsExpressionIndex = true
})
tikv.EnableFailpoints()

opts := []goleak.Option{
goleak.Cleanup(func(_ int) {
view.Stop()
}),
goleak.IgnoreTopFunction("github.com/golang/glog.(*fileSink).flushDaemon"),
goleak.IgnoreTopFunction("github.com/bazelbuild/rules_go/go/tools/bzltestutil.RegisterTimeoutHandler.func1"),
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.VerifyTestMain(m, opts...)
}
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 executor_test
package txn_test

import (
"fmt"
Expand Down
1 change: 0 additions & 1 deletion pkg/planner/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ go_test(
"logical_plan_trace_test.go",
"logical_plans_test.go",
"main_test.go",
"memtable_infoschema_extractor_test.go",
"optimizer_test.go",
"partition_pruning_test.go",
"physical_plan_test.go",
Expand Down
11 changes: 1 addition & 10 deletions pkg/planner/core/casetest/enforcempp/enforce_mpp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,16 +479,7 @@ func TestMPPMultiDistinct3Stage(t *testing.T) {
tk.MustExec("set @@session.tidb_allow_mpp=ON;")
// todo: current mock regionCache won't scale the regions among tiFlash nodes. The under layer still collect data from only one of the nodes.
tk.MustExec("split table t BETWEEN (0) AND (5000) REGIONS 5;")
tk.MustExec("insert into t values(1000, 1000, 1000, 1)")
tk.MustExec("insert into t values(1000, 1000, 1000, 1)")
tk.MustExec("insert into t values(2000, 2000, 2000, 1)")
tk.MustExec("insert into t values(2000, 2000, 2000, 1)")
tk.MustExec("insert into t values(3000, 3000, 3000, 1)")
tk.MustExec("insert into t values(3000, 3000, 3000, 1)")
tk.MustExec("insert into t values(4000, 4000, 4000, 1)")
tk.MustExec("insert into t values(4000, 4000, 4000, 1)")
tk.MustExec("insert into t values(5000, 5000, 5000, 1)")
tk.MustExec("insert into t values(5000, 5000, 5000, 1)")
tk.MustExec("insert into t values(1000, 1000, 1000, 1),(1000, 1000, 1000, 1),(2000, 2000, 2000, 1),(2000, 2000, 2000, 1),(3000, 3000, 3000, 1),(3000, 3000, 3000, 1),(4000, 4000, 4000, 1),(4000, 4000, 4000, 1),(5000, 5000, 5000, 1),(5000, 5000, 5000, 1)")

var input []string
var output []struct {
Expand Down
19 changes: 19 additions & 0 deletions pkg/planner/core/tests/extractor/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "extractor_test",
timeout = "short",
srcs = [
"main_test.go",
"memtable_infoschema_extractor_test.go",
],
flaky = True,
shard_count = 4,
deps = [
"//pkg/infoschema",
"//pkg/planner/core",
"//pkg/testkit",
"//pkg/testkit/testsetup",
"@org_uber_go_goleak//:goleak",
],
)
34 changes: 34 additions & 0 deletions pkg/planner/core/tests/extractor/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2024 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 extractor_test

import (
"flag"
"testing"

"github.com/pingcap/tidb/pkg/testkit/testsetup"
"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
testsetup.SetupForCommonTest()
flag.Parse()
opts := []goleak.Option{
goleak.IgnoreTopFunction("github.com/golang/glog.(*fileSink).flushDaemon"),
goleak.IgnoreTopFunction("github.com/bazelbuild/rules_go/go/tools/bzltestutil.RegisterTimeoutHandler.func1"),
goleak.IgnoreTopFunction("github.com/lestrrat-go/httprc.runFetchWorker"),
}
goleak.VerifyTestMain(m, opts...)
}
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 core_test
package extractor_test

import (
"fmt"
Expand Down

0 comments on commit 73f1cfe

Please sign in to comment.