From 7596439c863bf3888c3e2573ad52b3809cd2cf20 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Mon, 12 Dec 2022 14:34:04 +0800 Subject: [PATCH 1/2] *: stable tiflash test in ddl Signed-off-by: Weizhen Wang --- ddl/BUILD.bazel | 3 -- ddl/tiflashtest/BUILD.bazel | 35 ++++++++++++++++ ddl/{ => tiflashtest}/ddl_tiflash_test.go | 2 +- ddl/tiflashtest/main_test.go | 49 +++++++++++++++++++++++ 4 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 ddl/tiflashtest/BUILD.bazel rename ddl/{ => tiflashtest}/ddl_tiflash_test.go (99%) create mode 100644 ddl/tiflashtest/main_test.go diff --git a/ddl/BUILD.bazel b/ddl/BUILD.bazel index e5ef726cfc749..5d9d554f7b873 100644 --- a/ddl/BUILD.bazel +++ b/ddl/BUILD.bazel @@ -164,7 +164,6 @@ go_test( "ddl_api_test.go", "ddl_error_test.go", "ddl_test.go", - "ddl_tiflash_test.go", "ddl_worker_test.go", "ddl_workerpool_test.go", "export_test.go", @@ -234,7 +233,6 @@ go_test( "//store/gcworker", "//store/helper", "//store/mockstore", - "//store/mockstore/unistore", "//table", "//table/tables", "//tablecodec", @@ -256,7 +254,6 @@ go_test( "@com_github_ngaut_pools//:pools", "@com_github_pingcap_errors//:errors", "@com_github_pingcap_failpoint//:failpoint", - "@com_github_pingcap_kvproto//pkg/metapb", "@com_github_stretchr_testify//assert", "@com_github_stretchr_testify//require", "@com_github_tikv_client_go_v2//oracle", diff --git a/ddl/tiflashtest/BUILD.bazel b/ddl/tiflashtest/BUILD.bazel new file mode 100644 index 0000000000000..8854778def892 --- /dev/null +++ b/ddl/tiflashtest/BUILD.bazel @@ -0,0 +1,35 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_test") + +go_test( + name = "tiflashtest_test", + srcs = [ + "ddl_tiflash_test.go", + "main_test.go", + ], + flaky = True, + deps = [ + "//config", + "//ddl", + "//ddl/placement", + "//ddl/util", + "//domain", + "//domain/infosync", + "//kv", + "//parser/model", + "//session", + "//store/gcworker", + "//store/mockstore", + "//store/mockstore/unistore", + "//table", + "//testkit", + "//testkit/testsetup", + "//util", + "//util/logutil", + "@com_github_pingcap_failpoint//:failpoint", + "@com_github_pingcap_kvproto//pkg/metapb", + "@com_github_stretchr_testify//require", + "@com_github_tikv_client_go_v2//testutils", + "@org_uber_go_goleak//:goleak", + "@org_uber_go_zap//:zap", + ], +) diff --git a/ddl/ddl_tiflash_test.go b/ddl/tiflashtest/ddl_tiflash_test.go similarity index 99% rename from ddl/ddl_tiflash_test.go rename to ddl/tiflashtest/ddl_tiflash_test.go index accf7cc038ebd..a798fda7d9bf4 100644 --- a/ddl/ddl_tiflash_test.go +++ b/ddl/tiflashtest/ddl_tiflash_test.go @@ -16,7 +16,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSES/QL-LICENSE file. -package ddl_test +package tiflashtest import ( "context" diff --git a/ddl/tiflashtest/main_test.go b/ddl/tiflashtest/main_test.go new file mode 100644 index 0000000000000..68063ce27071b --- /dev/null +++ b/ddl/tiflashtest/main_test.go @@ -0,0 +1,49 @@ +// 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. + +// Copyright 2013 The ql Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSES/QL-LICENSE file. + +package tiflashtest + +import ( + "testing" + "time" + + "github.com/pingcap/tidb/config" + "github.com/pingcap/tidb/ddl" + "github.com/pingcap/tidb/testkit/testsetup" + "go.uber.org/goleak" +) + +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.(*loggingT).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...) +} From 3bfcd8e9f367007f7b917c5976d92856f4da567f Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Mon, 12 Dec 2022 14:55:49 +0800 Subject: [PATCH 2/2] *: stable tiflash test in ddl Signed-off-by: Weizhen Wang --- ddl/placement_sql_test.go | 2 +- ddl/tiflashtest/ddl_tiflash_test.go | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/ddl/placement_sql_test.go b/ddl/placement_sql_test.go index 5daca69feabec..b9af2af16e19d 100644 --- a/ddl/placement_sql_test.go +++ b/ddl/placement_sql_test.go @@ -588,7 +588,7 @@ func checkTiflashReplicaSet(t *testing.T, do *domain.Domain, db, tb string, cnt return } - CheckPlacementRule(infosync.GetMockTiFlash(), *infosync.MakeNewRule(tbl.Meta().ID, 1, nil)) + infosync.GetMockTiFlash().CheckPlacementRule(*infosync.MakeNewRule(tbl.Meta().ID, 1, nil)) require.NotNil(t, tiflashReplica) require.Equal(t, cnt, tiflashReplica.Count) } diff --git a/ddl/tiflashtest/ddl_tiflash_test.go b/ddl/tiflashtest/ddl_tiflash_test.go index a798fda7d9bf4..8922f7211f8b7 100644 --- a/ddl/tiflashtest/ddl_tiflash_test.go +++ b/ddl/tiflashtest/ddl_tiflash_test.go @@ -126,10 +126,6 @@ func ChangeGCSafePoint(tk *testkit.TestKit, t time.Time, enable string, lifeTime tk.MustExec(s) } -func CheckPlacementRule(tiflash *infosync.MockTiFlash, rule placement.TiFlashRule) bool { - return tiflash.CheckPlacementRule(rule) -} - func (s *tiflashContext) CheckFlashback(tk *testkit.TestKit, t *testing.T) { // If table is dropped after tikv_gc_safe_point, it can be recovered ChangeGCSafePoint(tk, time.Now().Add(-time.Hour), "false", "10m0s") @@ -524,7 +520,7 @@ func TestSetPlacementRuleNormal(t *testing.T) { tb, err := s.dom.InfoSchema().TableByName(model.NewCIStr("test"), model.NewCIStr("ddltiflash")) require.NoError(t, err) expectRule := infosync.MakeNewRule(tb.Meta().ID, 1, []string{"a", "b"}) - res := CheckPlacementRule(s.tiflash, *expectRule) + res := s.tiflash.CheckPlacementRule(*expectRule) require.True(t, res) // Set lastSafePoint to a timepoint in future, so all dropped table can be reckon as gc-ed. @@ -536,7 +532,7 @@ func TestSetPlacementRuleNormal(t *testing.T) { defer fCancelPD() tk.MustExec("drop table ddltiflash") expectRule = infosync.MakeNewRule(tb.Meta().ID, 1, []string{"a", "b"}) - res = CheckPlacementRule(s.tiflash, *expectRule) + res = s.tiflash.CheckPlacementRule(*expectRule) require.True(t, res) } @@ -580,7 +576,7 @@ func TestSetPlacementRuleWithGCWorker(t *testing.T) { require.NoError(t, err) expectRule := infosync.MakeNewRule(tb.Meta().ID, 1, []string{"a", "b"}) - res := CheckPlacementRule(s.tiflash, *expectRule) + res := s.tiflash.CheckPlacementRule(*expectRule) require.True(t, res) ChangeGCSafePoint(tk, time.Now().Add(-time.Hour), "true", "10m0s") @@ -590,7 +586,7 @@ func TestSetPlacementRuleWithGCWorker(t *testing.T) { // Wait GC time.Sleep(ddl.PollTiFlashInterval * RoundToBeAvailable) - res = CheckPlacementRule(s.tiflash, *expectRule) + res = s.tiflash.CheckPlacementRule(*expectRule) require.False(t, res) } @@ -611,7 +607,7 @@ func TestSetPlacementRuleFail(t *testing.T) { require.NoError(t, err) expectRule := infosync.MakeNewRule(tb.Meta().ID, 1, []string{}) - res := CheckPlacementRule(s.tiflash, *expectRule) + res := s.tiflash.CheckPlacementRule(*expectRule) require.False(t, res) }