mardi 26 janvier 2016

Akka Scala TestKit test PoisonPill message

Given that I have a Supervisor actor which is injected with a child actor how do I send the child a PoisonPill message and test this using TestKit?

Here is my Superivisor.

class Supervisor(child: ActorRef) extends Actor {

  ...
  child ! "hello"
  child ! PoisonPill
}

here is my test code

val probe = TestProbe()
val supervisor = system.actorOf(Props(classOf[Supervisor], probe.ref))
probe.expectMsg("hello")
probe.expectMsg(PoisonPill)

The problem is that the PoisonPill message is not received. Possibly because the probe is terminated by the PoisonPill message?

The assertion fails with

java.lang.AssertionError: assertion failed: timeout (3 seconds) 
during expectMsg while waiting for PoisonPill

Aucun commentaire:

Enregistrer un commentaire