Skip to content

Commit

Permalink
ttl,test: fix the datarace in TestShrinkScanWorkerTimeout (#57883)
Browse files Browse the repository at this point in the history
close #57876
  • Loading branch information
YangKeao authored Dec 2, 2024
1 parent 6d74071 commit 6434ca4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/ttl/ttlworker/task_manager_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,21 +381,25 @@ func TestShrinkScanWorkerTimeout(t *testing.T) {
isc := cache.NewInfoSchemaCache(time.Minute)
require.NoError(t, isc.Update(se))
m := ttlworker.NewTaskManager(context.Background(), pool, isc, "scan-manager-1", store)

startBlockNotifyCh := make(chan struct{})
blockCancelCh := make(chan struct{})

workers := []ttlworker.Worker{}
for j := 0; j < 4; j++ {
scanWorker := ttlworker.NewMockScanWorker(t)
if j == 0 {
scanWorker.SetCtx(func(ctx context.Context) context.Context {
return context.WithValue(ctx, ttlworker.TTLScanPostScanHookForTest{}, func() {
startBlockNotifyCh <- struct{}{}
<-blockCancelCh
})
})
}
scanWorker.Start()
workers = append(workers, scanWorker)
}

startBlockNotifyCh := make(chan struct{})
blockCancelCh := make(chan struct{})
workers[0].(ttlworker.WorkerTestExt).SetCtx(func(ctx context.Context) context.Context {
return context.WithValue(ctx, ttlworker.TTLScanPostScanHookForTest{}, func() {
startBlockNotifyCh <- struct{}{}
<-blockCancelCh
})
})
m.SetScanWorkers4Test(workers)

m.RescheduleTasks(se, now)
Expand Down

0 comments on commit 6434ca4

Please sign in to comment.