Skip to content

Commit 27d6b06

Browse files
committed
add another test race condition fix
1 parent c621dac commit 27d6b06

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

runnables/composite/runner_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,14 @@ func TestCompositeRunner_Run(t *testing.T) {
344344
t.Run("empty entries with later reload", func(t *testing.T) {
345345
t.Parallel()
346346

347+
// Channel to signal when Run() is called
348+
runStarted := make(chan struct{})
349+
347350
// Setup mock runnable for reload
348351
mockRunnable := mocks.NewMockRunnable()
349352
mockRunnable.On("String").Return("runnable1").Maybe()
350353
mockRunnable.On("Run", mock.Anything).Return(nil).Run(func(args mock.Arguments) {
354+
close(runStarted) // Signal that Run was called
351355
ctx := args.Get(0).(context.Context)
352356
<-ctx.Done() // Block until cancelled like a real service
353357
})
@@ -415,6 +419,14 @@ func TestCompositeRunner_Run(t *testing.T) {
415419
"Config should contain the mock runnable",
416420
)
417421

422+
// Wait for the new runnable to actually start
423+
select {
424+
case <-runStarted:
425+
// Run() was called, safe to proceed
426+
case <-time.After(2 * time.Second):
427+
t.Fatal("Timeout waiting for runnable to start after reload")
428+
}
429+
418430
// Cancel context to stop runner
419431
cancel()
420432

0 commit comments

Comments
 (0)