Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/core/Akka.TestKit.Tests/TestActorRefTests/TestProbeSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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; }
Expand All @@ -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;
}
}
}
}
11 changes: 10 additions & 1 deletion src/core/Akka.TestKit/DelegatingSupervisorStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Collections.Generic;
using System.Reflection;
using Akka.Actor;
using Akka.Actor.Internal;
using Akka.Util;
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/core/Akka.TestKit/Internal/InternalTestActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,7 @@ protected override void OnReceive(object message)
}
}
}

protected override SupervisorStrategy SupervisorStrategy() => _supervisorStrategy;
}
}