Skip to content

Commit e39b066

Browse files
authored
Use atomic.Bool in TestShutdown_WaitsForCompletion to fix data race (#151)
1 parent 6f0701a commit e39b066

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

app/jobs/heartbeatjob/heartbeatjob_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@ func TestShutdown_StopsJob(t *testing.T) {
162162
// TestShutdown_WaitsForCompletion - Shutdown() waits for goroutine to finish
163163
func TestShutdown_WaitsForCompletion(t *testing.T) {
164164
var wg sync.WaitGroup
165-
goroutineFinished := false
165+
var goroutineFinished atomic.Bool
166166

167167
svc := new(MockHeartbeatService)
168168

169169
job := NewWithConfig(HeartbeatJobConfig{
170170
Trigger: func(ctx context.Context, fn func() error) {
171171
<-ctx.Done()
172172
time.Sleep(20 * time.Millisecond)
173-
goroutineFinished = true
173+
goroutineFinished.Store(true)
174174
},
175175
})
176176

@@ -184,5 +184,5 @@ func TestShutdown_WaitsForCompletion(t *testing.T) {
184184
}()
185185

186186
wg.Wait()
187-
assert.True(t, goroutineFinished)
187+
assert.True(t, goroutineFinished.Load())
188188
}

0 commit comments

Comments
 (0)