diff --git a/src/core/Akka.TestKit.Tests/TestActorRefTests/TestProbeSpec.cs b/src/core/Akka.TestKit.Tests/TestActorRefTests/TestProbeSpec.cs index 483d144ea80..9c862177e6e 100644 --- a/src/core/Akka.TestKit.Tests/TestActorRefTests/TestProbeSpec.cs +++ b/src/core/Akka.TestKit.Tests/TestActorRefTests/TestProbeSpec.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using Akka.Actor; using Akka.TestKit.TestActors; using Akka.Util.Internal; @@ -89,6 +90,17 @@ public void TestProbe_restart_a_failing_child_if_the_given_supervisor_says_so() }); } + [Fact] + public async Task TestProbe_kill_a_failing_child_if_the_given_supervisor_says_so() + { + var restarts = new AtomicCounter(0); + var probe = CreateTestProbe(); + var child = await probe.ChildActorOfAsync(Props.Create(() => new FailingActor(restarts)), new FailOnExceptionStrategy()); + await WatchAsync(child); + child.Tell("hello"); + await ExpectTerminatedAsync(child); + } + class FailingActor : ActorBase { private AtomicCounter Restarts { get; } @@ -108,5 +120,13 @@ protected override void PostRestart(Exception reason) Restarts.IncrementAndGet(); } } + + private class FailOnExceptionStrategy: OneForOneStrategy + { + protected override Directive Handle(IActorRef child, Exception exception) + { + return Directive.Stop; + } + } } } diff --git a/src/core/Akka.TestKit/DelegatingSupervisorStrategy.cs b/src/core/Akka.TestKit/DelegatingSupervisorStrategy.cs index 07099200c27..e0649fb2667 100644 --- a/src/core/Akka.TestKit/DelegatingSupervisorStrategy.cs +++ b/src/core/Akka.TestKit/DelegatingSupervisorStrategy.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; +using System.Reflection; using Akka.Actor; using Akka.Actor.Internal; using Akka.Util; @@ -21,7 +22,15 @@ public class DelegatingSupervisorStrategy : SupervisorStrategy protected override Directive Handle(IActorRef child, Exception exception) { - throw new NotImplementedException(); + var childDelegate = Delegates[child]; + var handleMethod = typeof(SupervisorStrategy).GetMethod( + name: "Handle", + bindingAttr: BindingFlags.Instance | BindingFlags.NonPublic, + binder: Type.DefaultBinder, + types: new[] {typeof(IActorRef), typeof(Exception)}, + modifiers: null); + var result = (Directive) handleMethod.Invoke(childDelegate, new object[]{ child, exception }); + return result; } public override void ProcessFailure(IActorContext context, bool restart, IActorRef child, Exception cause, ChildRestartStats stats, diff --git a/src/core/Akka.TestKit/Internal/InternalTestActor.cs b/src/core/Akka.TestKit/Internal/InternalTestActor.cs index c722806e8da..47b9c88b5f9 100644 --- a/src/core/Akka.TestKit/Internal/InternalTestActor.cs +++ b/src/core/Akka.TestKit/Internal/InternalTestActor.cs @@ -102,5 +102,7 @@ protected override void OnReceive(object message) } } } + + protected override SupervisorStrategy SupervisorStrategy() => _supervisorStrategy; } }