Skip to content

Commit

Permalink
ddl: split partition test (#45994)
Browse files Browse the repository at this point in the history
ref #44940
  • Loading branch information
hawkingrei authored Aug 11, 2023
1 parent 0a5e0b3 commit 837afe3
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 3 deletions.
4 changes: 3 additions & 1 deletion build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@
"parser/parser.go": "parser/parser.go code",
"/cgo/": "ignore cgo code",
"external/": "no need to vet third party code",
"$GOROOT/": "ignore GOROOT code",
".*_generated\\.go$": "ignore generated code"
}
},
Expand Down Expand Up @@ -595,7 +596,8 @@
"br/pkg/lightning/mydump/": "more than 50",
"br/pkg/lightning/importer/": "more than 50",
"br/pkg/lightning/backend/local/": "more than 50",
"br/pkg/restore/": "more than 50"
"br/pkg/restore/": "more than 50",
"ddl/tests/partition/": "more than 50"
},
"only_files": {
"planer/core/casetest/binaryplan": "planer/core/casetest/binaryplan",
Expand Down
1 change: 0 additions & 1 deletion ddl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ go_test(
"db_change_test.go",
"db_foreign_key_test.go",
"db_integration_test.go",
"db_partition_test.go",
"db_rename_test.go",
"db_table_test.go",
"db_test.go",
Expand Down
46 changes: 46 additions & 0 deletions ddl/tests/partition/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "partition_test",
timeout = "short",
srcs = [
"db_partition_test.go",
"main_test.go",
],
flaky = True,
shard_count = 50,
deps = [
"//config",
"//ddl",
"//ddl/testutil",
"//ddl/util/callback",
"//domain",
"//errno",
"//kv",
"//parser/ast",
"//parser/model",
"//parser/mysql",
"//parser/terror",
"//session",
"//sessionctx",
"//sessionctx/variable",
"//sessiontxn",
"//store/mockstore",
"//table",
"//table/tables",
"//tablecodec",
"//testkit",
"//testkit/external",
"//testkit/testsetup",
"//types",
"//util/codec",
"//util/dbterror",
"//util/logutil",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@org_uber_go_goleak//:goleak",
"@org_uber_go_zap//:zap",
],
)
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 ddl_test
package partition

import (
"bytes"
Expand Down
72 changes: 72 additions & 0 deletions ddl/tests/partition/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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 partition

import (
"context"
"testing"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/testkit/testsetup"
"go.uber.org/goleak"
)

const (
// waitForCleanDataRound indicates how many times should we check data is cleaned or not.
waitForCleanDataRound = 150
// waitForCleanDataInterval is a min duration between 2 check for data clean.
waitForCleanDataInterval = time.Millisecond * 100
)

func TestMain(m *testing.M) {
testsetup.SetupForCommonTest()

config.UpdateGlobal(func(conf *config.Config) {
conf.TiKVClient.AsyncCommit.SafeWindow = 0
conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0
})

ddl.SetWaitTimeWhenErrorOccurred(time.Microsecond)

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...)
}

func backgroundExec(s kv.Storage, schema, sql string, done chan error) {
se, err := session.CreateSession4Test(s)
if err != nil {
done <- errors.Trace(err)
return
}
defer se.Close()
_, err = se.Execute(context.Background(), "use "+schema)
if err != nil {
done <- errors.Trace(err)
return
}
_, err = se.Execute(context.Background(), sql)
done <- errors.Trace(err)
}

0 comments on commit 837afe3

Please sign in to comment.