Skip to content

Commit 81c45f1

Browse files
Fix BackoffSupervisorSpec final stop message test race condition (#8032)
The test was flaky because: 1. It killed the child, waited for supervisor to restart it 2. Then sent the final stop message 3. Expected supervisor to terminate But the supervisor only terminates when the child stops AFTER the final stop message was received. The test needed to kill the child after sending the stop message. Fix: Wait for the restarted child (c2), send the stop message, then kill c2. This matches the expected behavior where the supervisor terminates because it received the final stop flag before the child stopped.
1 parent 99d7ea7 commit 81c45f1

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/core/Akka.Tests/Pattern/BackoffSupervisorSpec.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,31 @@ public async Task BackoffSupervisor_must_not_stop_when_final_stop_message_has_no
499499
await WatchAsync(c1);
500500
await supervisorWatcher.WatchAsync(supervisor);
501501

502+
// Kill child without sending final stop message first
502503
c1.Tell(PoisonPill.Instance);
503504
await ExpectTerminatedAsync(c1);
504-
supervisor.Tell("ping");
505-
await supervisorWatcher.ExpectNoMsgAsync(TimeSpan.FromMilliseconds(20)); // supervisor must not terminate
506505

506+
// Wait for the supervisor to restart the child (backoff delay is 100ms minimum)
507+
// This verifies that supervisor didn't stop - it restarted the child instead
508+
IActorRef c2 = null;
509+
await AwaitAssertAsync(async () =>
510+
{
511+
supervisor.Tell(BackoffSupervisor.GetCurrentChild.Instance);
512+
c2 = (await ExpectMsgAsync<BackoffSupervisor.CurrentChild>()).Ref;
513+
c2.Should().NotBeSameAs(c1);
514+
c2.IsNobody().Should().BeFalse();
515+
});
516+
517+
// Supervisor should still be alive (no final stop message received yet)
518+
await supervisorWatcher.ExpectNoMsgAsync(TimeSpan.FromMilliseconds(100));
519+
520+
// Now send the final stop message and kill the new child
521+
// The supervisor should terminate because it received the final stop message
522+
await WatchAsync(c2);
507523
supervisor.Tell(stopMessage);
524+
await ExpectMsgAsync(stopMessage); // Child echoes the message
525+
c2.Tell(PoisonPill.Instance);
526+
await ExpectTerminatedAsync(c2);
508527
await supervisorWatcher.ExpectTerminatedAsync(supervisor);
509528
}
510529
}

0 commit comments

Comments
 (0)