public void A_supervisor_must_send_notifications_to_supervisor_when_permanent_failure()
{
var countDownMessages = new CountdownEvent(1);
var countDownMax = new CountdownEvent(1);
var boss = ActorOf((cfg, ctx) =>
{
var crasher = ctx.ActorOf(Props.Create(() => new CountDownActor(countDownMessages, SupervisorStrategy.DefaultStrategy)), "crasher");
cfg.Receive("killCrasher", (s, context) => crasher.Tell(Kill.Instance));
cfg.Receive<Terminated>((terminated, context) => countDownMax.Signal());
cfg.Strategy = new OneForOneStrategy(1, TimeSpan.FromSeconds(5), e => Directive.Restart);
ctx.Watch(crasher);
}, "boss");
//We have built this hierarchy:
// boss
// |
// crasher
//We send "killCrasher" to boss, which in turn will send Kill to crasher making it crash.
//Crasher will be restarted, and during PostRestart countDownMessages will count down.
//We then send another "killCrasher", which again will send Kill to crasher. It crashes,
//decider says it should be restarted but since we specified maximum 1 restart/5seconds it will be
//permanently stopped. Boss, which watches crasher, receives Terminated, and counts down countDownMax
EventFilter.Exception<ActorKilledException>().Expect(2, () =>
{
boss.Tell("killCrasher");
boss.Tell("killCrasher");
});
countDownMessages.Wait(TimeSpan.FromSeconds(2)).ShouldBeTrue();
countDownMax.Wait(TimeSpan.FromSeconds(2)).ShouldBeTrue();
}