Site icon Jessitron

Testing in Akka: sneaky automatic restarts

Restarts are awesome when stuff fails and you want it to work. Akka does this by default for every actor, and that’s great in production. In testing, we’re looking for failure. We want to see it, not hide it. In testing, it’s sneaky of Akka to restart our whole actor hierarchy when it barfs.

Change this sneaky behavior in actor system configuration by altering the supervisor strategy of the guardian actor. The guardian is the parent of any actor created with system.actorOf(…), so its supervision strategy determines what happens when your whole hierarchy goes down.

Then, in your test’s assertions, make sure your actor hasn’t been terminated. If the guardian has a StoppingSupervisionStrategy and your actor goes down, it’ll stay down.

Code example in this gist.

Exit mobile version