Tuesday, May 8, 2018

Akka.NET–Testing the exceptional flow (Continued)

Yesterday I blogged about our approach to test Exceptions thrown by your Akka.NET actors. Today I want to talk about an issue we encountered when using our own ActorSystem.

In the example yesterday we were using the Sys property of the Akka.NET Testkit which gives us access to a built-in Actor System created for us:

var actor = Sys.ActorOf(Props.Create(() => new SampleActor()));

var filter = CreateEventFilter(Sys);

However when we tried to run the same test but using our own ActorSystem instance instead the test failed and no Exception was received by the EventFilter.

To understand why this fails, you have to understand what TestKit is doing behind the scenes when creating an ActorSystem for you. For every test you run it creates a new ActorSystem instance using the following configuration:

The important line here is the following:

loggers = ["Akka.TestKit.TestEventListener, Akka.TestKit"]

This line will link the TestKit EventFilter to the ActorSystem. As we didn’t had any configuration setup for our own ActorSystem, the EventFilter didn’t pick up any event.

To fix it, we included the configuration above in our app.config:

No comments: