@@ -400,24 +400,33 @@ func TestConnStateMachine_FIFOOrdering(t *testing.T) {
400400 var executionOrder []int
401401 var orderMu sync.Mutex
402402 var wg sync.WaitGroup
403- var startBarrier sync.WaitGroup
404- startBarrier .Add (numGoroutines )
403+
404+ // Use channels to ensure deterministic queueing order
405+ // Each goroutine waits for the previous one to queue before it queues
406+ queuedChannels := make ([]chan struct {}, numGoroutines )
407+ for i := 0 ; i < numGoroutines ; i ++ {
408+ queuedChannels [i ] = make (chan struct {})
409+ }
405410
406411 // Launch goroutines that will all wait
407412 for i := 0 ; i < numGoroutines ; i ++ {
408413 wg .Add (1 )
409414 go func (id int ) {
410415 defer wg .Done ()
411416
412- // Wait for all goroutines to be ready
413- startBarrier .Done ()
414- startBarrier .Wait ()
417+ // Wait for previous goroutine to queue (except for goroutine 0)
418+ if id > 0 {
419+ <- queuedChannels [id - 1 ]
420+ }
415421
416- // Small stagger to ensure queue order
417- time .Sleep (time . Duration ( id ) * time .Millisecond )
422+ // Small delay to ensure the previous goroutine's AwaitAndTransition has been called
423+ time .Sleep (5 * time .Millisecond )
418424
419425 ctx := context .Background ()
420426
427+ // Signal that we're about to queue
428+ close (queuedChannels [id ])
429+
421430 // This should queue in FIFO order
422431 _ , err := sm .AwaitAndTransition (ctx , []ConnState {StateIdle }, StateInitializing )
423432 if err != nil {
@@ -437,7 +446,8 @@ func TestConnStateMachine_FIFOOrdering(t *testing.T) {
437446 }(i )
438447 }
439448
440- // Wait a bit for all goroutines to queue up
449+ // Wait for all goroutines to queue up
450+ <- queuedChannels [numGoroutines - 1 ]
441451 time .Sleep (50 * time .Millisecond )
442452
443453 // Transition to READY to start processing the queue
0 commit comments