Skip to content

Commit 8e898a0

Browse files
committed
Fix race in test
1 parent 75d9837 commit 8e898a0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

internal/worker/worker_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ func TestWorker_FullWorkflow(t *testing.T) {
537537
// Track processed tasks
538538
var processedTasks int32
539539
var taskResults []*testResult
540+
var mu sync.Mutex
540541

541542
task1 := &testTask{ID: 1, Data: "task1"}
542543
task2 := &testTask{ID: 2, Data: "task2"}
@@ -553,10 +554,14 @@ func TestWorker_FullWorkflow(t *testing.T) {
553554

554555
mockTaskWorker.On("Execute", mock.Anything, task1).Return(result1, nil).Run(func(args mock.Arguments) {
555556
atomic.AddInt32(&processedTasks, 1)
557+
mu.Lock()
558+
defer mu.Unlock()
556559
taskResults = append(taskResults, result1)
557560
})
558561
mockTaskWorker.On("Execute", mock.Anything, task2).Return(result2, nil).Run(func(args mock.Arguments) {
559562
atomic.AddInt32(&processedTasks, 1)
563+
mu.Lock()
564+
defer mu.Unlock()
560565
taskResults = append(taskResults, result2)
561566
})
562567

0 commit comments

Comments
 (0)