Skip to content

Commit

Permalink
dxf: fix flaky scope test (#57796)
Browse files Browse the repository at this point in the history
ref #57497
  • Loading branch information
D3Hunter authored Nov 28, 2024
1 parent 65e233e commit 2950725
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pkg/disttask/framework/integrationtests/framework_scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,15 @@ func TestScopeBasic(t *testing.T) {
tk.MustQuery("select @@global.tidb_service_scope").Check(testkit.Rows("background"))
tk.MustQuery("select @@tidb_service_scope").Check(testkit.Rows("background"))

var fpEnabled atomic.Bool
ch := make(chan struct{})
fpEnabled.Store(true)
var counter atomic.Int32
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/disttask/framework/scheduler/syncRefresh", func() {
if fpEnabled.Load() {
if counter.Add(1) == 1 {
ch <- struct{}{}
}
})
<-ch
taskID = submitTaskAndCheckSuccessForScope(c.Ctx, t, "😊", nodeCnt, "background", c.TestContext)
fpEnabled.Store(false)

tk.MustQuery(`select role from mysql.dist_framework_meta where host=":4000"`).Check(testkit.Rows("background"))
tk.MustQuery(`select role from mysql.dist_framework_meta where host=":4001"`).Check(testkit.Rows(""))
Expand All @@ -101,10 +99,15 @@ func TestScopeBasic(t *testing.T) {
// 3. 2 "background" role.
tk.MustExec("update mysql.dist_framework_meta set role = \"background\" where host = \":4001\"")
time.Sleep(5 * time.Second)
fpEnabled.Store(true)
<-ch
ch2 := make(chan struct{})
var counter2 atomic.Int32
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/disttask/framework/scheduler/syncRefresh", func() {
if counter2.Add(1) == 1 {
ch2 <- struct{}{}
}
})
<-ch2
taskID = submitTaskAndCheckSuccessForScope(c.Ctx, t, "😆", nodeCnt, "background", c.TestContext)
fpEnabled.Store(false)
checkSubtaskOnNodes(c.Ctx, t, taskID, []string{":4000", ":4001"})
tk.MustQuery(`select role from mysql.dist_framework_meta where host=":4000"`).Check(testkit.Rows("background"))
tk.MustQuery(`select role from mysql.dist_framework_meta where host=":4001"`).Check(testkit.Rows("background"))
Expand Down Expand Up @@ -153,19 +156,17 @@ func runTargetScopeCase(t *testing.T, c *testutil.TestDXFContext, tk *testkit.Te
for i := 0; i < len(testCase.nodeScopes); i++ {
tk.MustExec(fmt.Sprintf("update mysql.dist_framework_meta set role = \"%s\" where host = \"%s\"", testCase.nodeScopes[i], c.GetNodeIDByIdx(i)))
}
var fpEnabled atomic.Bool
ch := make(chan struct{})
fpEnabled.Store(true)
var counter atomic.Int32
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/disttask/framework/scheduler/syncRefresh", func() {
if fpEnabled.Load() {
if counter.Add(1) <= 3 {
ch <- struct{}{}
}
})
<-ch
<-ch
<-ch
taskID := submitTaskAndCheckSuccessForScope(c.Ctx, t, "task"+strconv.Itoa(idx), nodeCnt, testCase.scope, c.TestContext)
fpEnabled.Store(false)
expected := make([]string, 0)
for i, scope := range testCase.nodeScopes {
if scope == testCase.scope {
Expand Down

0 comments on commit 2950725

Please sign in to comment.