From dd94777dd027dcb4f6c5dd5b8153320bc5ae9060 Mon Sep 17 00:00:00 2001 From: Calvin Neo Date: Mon, 14 Mar 2022 16:27:51 +0800 Subject: [PATCH] ddl: fix data race in TestTiFlashBatchRateLimiter (#33006) close pingcap/tidb#33005 --- ddl/ddl_tiflash_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ddl/ddl_tiflash_test.go b/ddl/ddl_tiflash_test.go index efe0b113ca48c..a760b9228fb6e 100644 --- a/ddl/ddl_tiflash_test.go +++ b/ddl/ddl_tiflash_test.go @@ -22,6 +22,7 @@ import ( "context" "fmt" "math" + "sync" "sync/atomic" "testing" "time" @@ -887,12 +888,17 @@ func TestTiFlashBatchRateLimiter(t *testing.T) { // Retrigger, but close session before the whole job ends. var wg util.WaitGroupWrapper + var mu sync.Mutex wg.Run(func() { time.Sleep(time.Millisecond * 20) + mu.Lock() + defer mu.Unlock() tk.Session().Close() logutil.BgLogger().Info("session closed") }) + mu.Lock() timeOut, err = execWithTimeout(t, tk, time.Second*2, "alter database tiflash_ddl_limit set tiflash replica 1") + mu.Unlock() require.NoError(t, err) require.False(t, timeOut) check(5, 5)