Skip to content

Commit

Permalink
executor: split test for aggregate (#44987)
Browse files Browse the repository at this point in the history
ref #44940
  • Loading branch information
hawkingrei authored Jun 27, 2023
1 parent dd911e7 commit 8ef5b4a
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 41 deletions.
1 change: 0 additions & 1 deletion executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ go_test(
timeout = "moderate",
srcs = [
"adapter_test.go",
"aggregate_test.go",
"analyze_test.go",
"apply_cache_test.go",
"batch_point_get_test.go",
Expand Down
9 changes: 9 additions & 0 deletions executor/internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "internal",
srcs = ["testkit.go"],
importpath = "github.com/pingcap/tidb/executor/internal",
visibility = ["//executor:__subpackages__"],
deps = ["//testkit"],
)
31 changes: 31 additions & 0 deletions executor/internal/testkit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 internal

import (
"fmt"

"github.com/pingcap/tidb/testkit"
)

// FillData fill data into table
func FillData(tk *testkit.TestKit, table string) {
tk.MustExec("use test")
tk.MustExec(fmt.Sprintf("create table %s(id int not null default 1, name varchar(255), PRIMARY KEY(id));", table))

// insert data
tk.MustExec(fmt.Sprintf("insert INTO %s VALUES (1, \"hello\");", table))
tk.MustExec(fmt.Sprintf("insert into %s values (2, \"hello\");", table))
}
14 changes: 0 additions & 14 deletions executor/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
package executor_test

import (
"fmt"
"testing"

"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/meta/autoid"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/testkit/testdata"
"github.com/pingcap/tidb/testkit/testmain"
"github.com/pingcap/tidb/testkit/testsetup"
Expand All @@ -30,19 +28,16 @@ import (

var testDataMap = make(testdata.BookKeeper)
var prepareMergeSuiteData testdata.TestData
var aggMergeSuiteData testdata.TestData
var executorSuiteData testdata.TestData
var pointGetSuiteData testdata.TestData
var slowQuerySuiteData testdata.TestData

func TestMain(m *testing.M) {
testsetup.SetupForCommonTest()
testDataMap.LoadTestSuiteData("testdata", "agg_suite")
testDataMap.LoadTestSuiteData("testdata", "executor_suite")
testDataMap.LoadTestSuiteData("testdata", "prepare_suite")
testDataMap.LoadTestSuiteData("testdata", "point_get_suite")
testDataMap.LoadTestSuiteData("testdata", "slow_query_suite")
aggMergeSuiteData = testDataMap["agg_suite"]
executorSuiteData = testDataMap["executor_suite"]
prepareMergeSuiteData = testDataMap["prepare_suite"]
pointGetSuiteData = testDataMap["point_get_suite"]
Expand Down Expand Up @@ -75,12 +70,3 @@ func TestMain(m *testing.M) {

goleak.VerifyTestMain(testmain.WrapTestingM(m, callback), opts...)
}

func fillData(tk *testkit.TestKit, table string) {
tk.MustExec("use test")
tk.MustExec(fmt.Sprintf("create table %s(id int not null default 1, name varchar(255), PRIMARY KEY(id));", table))

// insert data
tk.MustExec(fmt.Sprintf("insert INTO %s VALUES (1, \"hello\");", table))
tk.MustExec(fmt.Sprintf("insert into %s values (2, \"hello\");", table))
}
28 changes: 28 additions & 0 deletions executor/test/aggregate/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "aggregate_test",
timeout = "short",
srcs = [
"aggregate_test.go",
"main_test.go",
],
data = glob(["testdata/**"]),
flaky = True,
shard_count = 38,
deps = [
"//executor",
"//executor/internal",
"//parser/terror",
"//planner/core",
"//session",
"//sessionctx/variable",
"//testkit",
"//testkit/testdata",
"//testkit/testsetup",
"//util/sqlexec",
"@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 executor_test
package aggregate

import (
"context"
Expand All @@ -27,6 +27,7 @@ import (

"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/executor/internal"
"github.com/pingcap/tidb/parser/terror"
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/session"
Expand Down Expand Up @@ -650,7 +651,7 @@ func TestSelectDistinct(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
fillData(tk, "select_distinct_test")
internal.FillData(tk, "select_distinct_test")

tk.MustExec("begin")
r := tk.MustQuery("select distinct name from select_distinct_test;")
Expand Down
38 changes: 38 additions & 0 deletions executor/test/aggregate/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2022 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 aggregate

import (
"testing"

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

var aggMergeSuiteData testdata.TestData
var testDataMap = make(testdata.BookKeeper)

func TestMain(m *testing.M) {
testsetup.SetupForCommonTest()
testDataMap.LoadTestSuiteData("testdata", "agg_suite")
aggMergeSuiteData = testDataMap["agg_suite"]
opts := []goleak.Option{
goleak.IgnoreTopFunction("github.com/golang/glog.(*fileSink).flushDaemon"),
goleak.IgnoreTopFunction("github.com/lestrrat-go/httprc.runFetchWorker"),
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
}
goleak.VerifyTestMain(m, opts...)
}
File renamed without changes.
File renamed without changes.
11 changes: 0 additions & 11 deletions executor/test/loaddatatest/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
package loaddatatest

import (
"fmt"
"testing"

"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/meta/autoid"
"github.com/pingcap/tidb/testkit"
"github.com/tikv/client-go/v2/tikv"
"go.opencensus.io/stats/view"
"go.uber.org/goleak"
Expand Down Expand Up @@ -49,12 +47,3 @@ func TestMain(m *testing.M) {

goleak.VerifyTestMain(m, opts...)
}

func fillData(tk *testkit.TestKit, table string) {
tk.MustExec("use test")
tk.MustExec(fmt.Sprintf("create table %s(id int not null default 1, name varchar(255), PRIMARY KEY(id));", table))

// insert data
tk.MustExec(fmt.Sprintf("insert INTO %s VALUES (1, \"hello\");", table))
tk.MustExec(fmt.Sprintf("insert into %s values (2, \"hello\");", table))
}
1 change: 1 addition & 0 deletions executor/test/writetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go_test(
"//br/pkg/lightning/mydump",
"//config",
"//executor",
"//executor/internal",
"//kv",
"//meta/autoid",
"//parser/model",
Expand Down
11 changes: 0 additions & 11 deletions executor/test/writetest/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
package writetest

import (
"fmt"
"testing"

"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/meta/autoid"
"github.com/pingcap/tidb/testkit"
"github.com/tikv/client-go/v2/tikv"
"go.opencensus.io/stats/view"
"go.uber.org/goleak"
Expand Down Expand Up @@ -49,12 +47,3 @@ func TestMain(m *testing.M) {

goleak.VerifyTestMain(m, opts...)
}

func fillData(tk *testkit.TestKit, table string) {
tk.MustExec("use test")
tk.MustExec(fmt.Sprintf("create table %s(id int not null default 1, name varchar(255), PRIMARY KEY(id));", table))

// insert data
tk.MustExec(fmt.Sprintf("insert INTO %s VALUES (1, \"hello\");", table))
tk.MustExec(fmt.Sprintf("insert into %s values (2, \"hello\");", table))
}
5 changes: 3 additions & 2 deletions executor/test/writetest/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pingcap/tidb/br/pkg/lightning/mydump"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/executor/internal"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
Expand Down Expand Up @@ -1327,7 +1328,7 @@ func TestMultipleTableUpdate(t *testing.T) {
func TestDelete(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
fillData(tk, "delete_test")
internal.FillData(tk, "delete_test")

tk.MustExec(`update delete_test set name = "abc" where id = 2;`)
tk.CheckExecResult(1, 0)
Expand Down Expand Up @@ -3128,7 +3129,7 @@ func TestUpdate(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
fillData(tk, "update_test")
internal.FillData(tk, "update_test")

updateStr := `UPDATE update_test SET name = "abc" where id > 0;`
tk.MustExec(updateStr)
Expand Down

0 comments on commit 8ef5b4a

Please sign in to comment.