Skip to content

Commit

Permalink
*: stable tiflash test in ddl (#39825)
Browse files Browse the repository at this point in the history
close #39831
  • Loading branch information
hawkingrei authored Dec 12, 2022
1 parent 965ed00 commit c8b5c3b
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 14 deletions.
3 changes: 0 additions & 3 deletions ddl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -234,7 +233,6 @@ go_test(
"//store/gcworker",
"//store/helper",
"//store/mockstore",
"//store/mockstore/unistore",
"//table",
"//table/tables",
"//tablecodec",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion ddl/placement_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
35 changes: 35 additions & 0 deletions ddl/tiflashtest/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
16 changes: 6 additions & 10 deletions ddl/ddl_tiflash_test.go → ddl/tiflashtest/ddl_tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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.
Expand All @@ -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)
}

Expand Down Expand Up @@ -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")
Expand All @@ -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)
}

Expand All @@ -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)
}

Expand Down
49 changes: 49 additions & 0 deletions ddl/tiflashtest/main_test.go
Original file line number Diff line number Diff line change
@@ -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...)
}

0 comments on commit c8b5c3b

Please sign in to comment.