Skip to content

Commit

Permalink
tables: split partiton test (#46252)
Browse files Browse the repository at this point in the history
ref #44940
  • Loading branch information
hawkingrei committed Aug 28, 2023
1 parent 2a4a60c commit e7e9fb6
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 39 deletions.
1 change: 0 additions & 1 deletion executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ go_test(
"@com_github_pingcap_kvproto//pkg/metapb",
"@com_github_pingcap_log//:log",
"@com_github_pingcap_sysutil//:sysutil",
"@com_github_pingcap_tipb//go-binlog",
"@com_github_pingcap_tipb//go-tipb",
"@com_github_prometheus_client_golang//prometheus",
"@com_github_prometheus_client_model//go",
Expand Down
15 changes: 1 addition & 14 deletions executor/executor_txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package executor_test

import (
"context"
"fmt"
"strconv"
"strings"
Expand All @@ -25,9 +24,7 @@ import (
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/sessionctx/binloginfo"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tipb/go-binlog"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
)

func TestInvalidReadTemporaryTable(t *testing.T) {
Expand Down Expand Up @@ -769,7 +766,7 @@ func TestSavepointWithBinlog(t *testing.T) {

tk := testkit.NewTestKit(t, store)
// mock for binlog enabled.
tk.Session().GetSessionVars().BinlogClient = binloginfo.MockPumpsClient(&mockPumpClient{})
tk.Session().GetSessionVars().BinlogClient = binloginfo.MockPumpsClient(&testkit.MockPumpClient{})
tk.MustExec("use test")
tk.MustExec("create table t(id int, a int, unique index idx(id))")

Expand All @@ -788,13 +785,3 @@ func TestSavepointWithBinlog(t *testing.T) {
tk.MustExec("commit")
tk.MustQuery("select * from t").Check(testkit.Rows("1 1"))
}

type mockPumpClient struct{}

func (m mockPumpClient) WriteBinlog(ctx context.Context, in *binlog.WriteBinlogReq, opts ...grpc.CallOption) (*binlog.WriteBinlogResp, error) {
return &binlog.WriteBinlogResp{}, nil
}

func (m mockPumpClient) PullBinlogs(ctx context.Context, in *binlog.PullBinlogReq, opts ...grpc.CallOption) (binlog.Pump_PullBinlogsClient, error) {
return nil, nil
}
13 changes: 3 additions & 10 deletions table/tables/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ go_library(
"partition.go",
"state_remote.go",
"tables.go",
"testutil.go",
],
importpath = "github.com/pingcap/tidb/table/tables",
visibility = ["//visibility:public"],
Expand Down Expand Up @@ -61,20 +62,18 @@ go_library(

go_test(
name = "tables_test",
timeout = "long",
timeout = "short",
srcs = [
"cache_test.go",
"export_test.go",
"index_test.go",
"main_test.go",
"mutation_checker_test.go",
"partition_test.go",
"state_remote_test.go",
"tables_test.go",
],
embed = [":tables"],
flaky = True,
shard_count = 50,
shard_count = 36,
deps = [
"//ddl",
"//ddl/util/callback",
Expand All @@ -91,7 +90,6 @@ go_test(
"//parser/mysql",
"//session",
"//sessionctx",
"//sessionctx/binloginfo",
"//sessionctx/stmtctx",
"//sessionctx/variable",
"//sessiontxn",
Expand All @@ -105,20 +103,15 @@ go_test(
"//util",
"//util/codec",
"//util/collate",
"//util/dbterror",
"//util/logutil",
"//util/mock",
"//util/rowcodec",
"//util/stmtsummary",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_pingcap_tipb//go-binlog",
"@com_github_prometheus_client_model//go",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@com_github_tikv_client_go_v2//oracle",
"@org_golang_google_grpc//:grpc",
"@org_uber_go_goleak//:goleak",
"@org_uber_go_zap//:zap",
],
)
12 changes: 0 additions & 12 deletions table/tables/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/rowcodec"
"github.com/pingcap/tipb/go-binlog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
)

func firstKey(t table.Table) kv.Key {
Expand Down Expand Up @@ -81,16 +79,6 @@ func seek(t table.PhysicalTable, ctx sessionctx.Context, h kv.Handle) (kv.Handle
return handle, true, nil
}

type mockPumpClient struct{}

func (m mockPumpClient) WriteBinlog(ctx context.Context, in *binlog.WriteBinlogReq, opts ...grpc.CallOption) (*binlog.WriteBinlogResp, error) {
return &binlog.WriteBinlogResp{}, nil
}

func (m mockPumpClient) PullBinlogs(ctx context.Context, in *binlog.PullBinlogReq, opts ...grpc.CallOption) (binlog.Pump_PullBinlogsClient, error) {
return nil, nil
}

func TestBasic(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
Expand Down
32 changes: 32 additions & 0 deletions table/tables/test/partition/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "partition_test",
timeout = "long",
srcs = [
"main_test.go",
"partition_test.go",
],
flaky = True,
shard_count = 35,
deps = [
"//ddl",
"//domain",
"//errno",
"//kv",
"//parser/model",
"//sessionctx/binloginfo",
"//sessiontxn",
"//table",
"//table/tables",
"//testkit",
"//testkit/testsetup",
"//types",
"//util",
"//util/dbterror",
"//util/logutil",
"@com_github_stretchr_testify//require",
"@org_uber_go_goleak//:goleak",
"@org_uber_go_zap//:zap",
],
)
33 changes: 33 additions & 0 deletions table/tables/test/partition/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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 (
"testing"

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

func TestMain(m *testing.M) {
testsetup.SetupForCommonTest()
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("go.opencensus.io/stats/view.(*worker).start"),
}
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 tables_test
package partition

import (
"context"
Expand Down Expand Up @@ -45,7 +45,7 @@ func TestPartitionBasic(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.Session().GetSessionVars().BinlogClient = binloginfo.MockPumpsClient(mockPumpClient{})
tk.Session().GetSessionVars().BinlogClient = binloginfo.MockPumpsClient(testkit.MockPumpClient{})
tk.MustExec("set @@session.tidb_enable_table_partition = '1'")
tk.MustExec(`CREATE TABLE partition_basic (id int(11), unique index(id))
PARTITION BY RANGE COLUMNS ( id ) (
Expand Down
1 change: 1 addition & 0 deletions table/tables/export_test.go → table/tables/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package tables

import "github.com/pingcap/tidb/table"

// SwapReorgPartFields swaps the reorganizePartitions field of two partitioned tables. used in tests.
func SwapReorgPartFields(src, dst table.Table) bool {
s, ok := src.(*partitionedTable)
if !ok {
Expand Down
2 changes: 2 additions & 0 deletions testkit/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ go_library(
"//util/sqlexec",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_pingcap_tipb//go-binlog",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@com_github_tikv_client_go_v2//tikv",
"@com_github_tikv_client_go_v2//tikvrpc",
"@io_opencensus_go//stats/view",
"@org_golang_google_grpc//:grpc",
"@org_uber_go_atomic//:atomic",
"@org_uber_go_zap//:zap",
],
Expand Down
15 changes: 15 additions & 0 deletions testkit/testkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ import (
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/intest"
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tipb/go-binlog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tikv/client-go/v2/tikv"
"github.com/tikv/client-go/v2/tikvrpc"
"go.uber.org/atomic"
"google.golang.org/grpc"
)

var testKitIDGenerator atomic.Uint64
Expand Down Expand Up @@ -569,3 +571,16 @@ func (c *RegionProperityClient) SendRequest(ctx context.Context, addr string, re
}
return c.Client.SendRequest(ctx, addr, req, timeout)
}

// MockPumpClient is a mock pump client.
type MockPumpClient struct{}

// WriteBinlog is a mock method.
func (m MockPumpClient) WriteBinlog(ctx context.Context, in *binlog.WriteBinlogReq, opts ...grpc.CallOption) (*binlog.WriteBinlogResp, error) {
return &binlog.WriteBinlogResp{}, nil
}

// PullBinlogs is a mock method.
func (m MockPumpClient) PullBinlogs(ctx context.Context, in *binlog.PullBinlogReq, opts ...grpc.CallOption) (binlog.Pump_PullBinlogsClient, error) {
return nil, nil
}

0 comments on commit e7e9fb6

Please sign in to comment.