From 175cd377e8e9aa173a2dca23b071c65e479bec70 Mon Sep 17 00:00:00 2001 From: Roger Johansson Date: Fri, 22 Aug 2025 13:05:31 +0200 Subject: [PATCH] Use probe to await child restart --- .../SupervisionTests_AlwaysRestart.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/Proto.Actor.Tests/SupervisionTests_AlwaysRestart.cs b/tests/Proto.Actor.Tests/SupervisionTests_AlwaysRestart.cs index ce021f1c70..96a1badc21 100644 --- a/tests/Proto.Actor.Tests/SupervisionTests_AlwaysRestart.cs +++ b/tests/Proto.Actor.Tests/SupervisionTests_AlwaysRestart.cs @@ -20,7 +20,13 @@ public async Task AlwaysRestartStrategy_Should_RestartFailingChildOnly() var child2Started = 0; var strategy = new AlwaysRestartStrategy(); - var child1Props = Props.FromProducer(() => new ChildActor(() => child1Started++)); + // attach a probe to the failing child to observe its mailbox + var (probe, probePid) = system.CreateTestProbe(); + context.Send(probePid, "start"); + await probe.FishForMessageAsync(); + + var child1Props = Props.FromProducer(() => new ChildActor(() => child1Started++)) + .WithMailboxProbe(probe); var child2Props = Props.FromProducer(() => new ChildActor(() => child2Started++)); var parentProps = Props.FromProducer(() => new ParentActor(child1Props, child2Props)) @@ -30,7 +36,8 @@ public async Task AlwaysRestartStrategy_Should_RestartFailingChildOnly() context.Send(parent, "fail"); - await Task.Delay(1000); + // Wait for the restart system message instead of relying on elapsed time + await probe.FishForMessageAsync(); Assert.Equal(2, child1Started); Assert.Equal(1, child2Started);