Skip to content

Commit

Permalink
stop TTL in test to avoid data race
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Keao <yangkeao@chunibyo.icu>
  • Loading branch information
YangKeao committed Aug 17, 2023
1 parent 4ca6a36 commit 8239759
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions br/pkg/restore/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ go_test(
"//tablecodec",
"//testkit",
"//testkit/testsetup",
"//ttl/ttlworker",
"//types",
"//util/codec",
"@com_github_fsouza_fake_gcs_server//fakestorage",
Expand Down
4 changes: 4 additions & 0 deletions br/pkg/restore/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions ttl/ttlworker/job_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 8239759

Please sign in to comment.