From 82397590c9ecf65451150a1c240c4aa35098288e Mon Sep 17 00:00:00 2001 From: Yang Keao Date: Thu, 17 Aug 2023 14:37:53 +0800 Subject: [PATCH] stop TTL in test to avoid data race Signed-off-by: Yang Keao --- br/pkg/restore/BUILD.bazel | 1 + br/pkg/restore/db_test.go | 4 ++++ ttl/ttlworker/job_manager.go | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/br/pkg/restore/BUILD.bazel b/br/pkg/restore/BUILD.bazel index 772ec438976d7..d2665142075e8 100644 --- a/br/pkg/restore/BUILD.bazel +++ b/br/pkg/restore/BUILD.bazel @@ -149,6 +149,7 @@ go_test( "//tablecodec", "//testkit", "//testkit/testsetup", + "//ttl/ttlworker", "//types", "//util/codec", "@com_github_fsouza_fake_gcs_server//fakestorage", diff --git a/br/pkg/restore/db_test.go b/br/pkg/restore/db_test.go index 8801a6af34727..d0c7f702092f5 100644 --- a/br/pkg/restore/db_test.go +++ b/br/pkg/restore/db_test.go @@ -24,6 +24,7 @@ import ( "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/parser/types" "github.com/pingcap/tidb/testkit" + "github.com/pingcap/tidb/ttl/ttlworker" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tikv/client-go/v2/oracle" @@ -368,9 +369,12 @@ func TestFilterDDLJobByRules(t *testing.T) { } func TestGetExistedUserDBs(t *testing.T) { + ttlworker.SkipTTLJobManager4Test = true + m, err := mock.NewCluster() require.Nil(t, err) defer m.Stop() + dom := m.Domain dbs := restore.GetExistedUserDBs(dom) diff --git a/ttl/ttlworker/job_manager.go b/ttl/ttlworker/job_manager.go index 8a9a3c17d48cf..a7417dd084693 100644 --- a/ttl/ttlworker/job_manager.go +++ b/ttl/ttlworker/job_manager.go @@ -44,6 +44,9 @@ const updateHeartBeatTemplate = "UPDATE mysql.tidb_ttl_table_status SET current_ const timeFormat = "2006-01-02 15:04:05" +// SkipTTLJobManager4Test skips the bootstrap of TTLJobManager if it's true. It's used to avoid data race in test. +var SkipTTLJobManager4Test bool + func insertNewTableIntoStatusSQL(tableID int64, parentTableID int64) (string, []interface{}) { return insertNewTableIntoStatusTemplate, []interface{}{tableID, parentTableID} } @@ -99,6 +102,13 @@ func NewJobManager(id string, sessPool sessionPool, store kv.Storage) (manager * manager.delCh = make(chan *ttlDeleteTask) manager.notifyStateCh = make(chan interface{}, 1) + if SkipTTLJobManager4Test { + manager.init(func() error { + return nil + }) + return + } + manager.init(manager.jobLoop) manager.ctx = logutil.WithKeyValue(manager.ctx, "ttl-worker", "manager")