diff --git a/build/nogo_config.json b/build/nogo_config.json index abcd9d3444bf2..00a6c363f16ba 100644 --- a/build/nogo_config.json +++ b/build/nogo_config.json @@ -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" } }, @@ -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", diff --git a/ddl/BUILD.bazel b/ddl/BUILD.bazel index 2cabeac33b2b9..399ce5017a1f7 100644 --- a/ddl/BUILD.bazel +++ b/ddl/BUILD.bazel @@ -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", diff --git a/ddl/tests/partition/BUILD.bazel b/ddl/tests/partition/BUILD.bazel new file mode 100644 index 0000000000000..b0ee39b9898ad --- /dev/null +++ b/ddl/tests/partition/BUILD.bazel @@ -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", + ], +) diff --git a/ddl/db_partition_test.go b/ddl/tests/partition/db_partition_test.go similarity index 99% rename from ddl/db_partition_test.go rename to ddl/tests/partition/db_partition_test.go index d749177a3b269..abf22c951aaa1 100644 --- a/ddl/db_partition_test.go +++ b/ddl/tests/partition/db_partition_test.go @@ -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" diff --git a/ddl/tests/partition/main_test.go b/ddl/tests/partition/main_test.go new file mode 100644 index 0000000000000..b9ce2882125fb --- /dev/null +++ b/ddl/tests/partition/main_test.go @@ -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) +}