I'm trying to unit test my actor's handling of a "Terminated" message for a child actor. The code under test is something like this:
case Terminated(terminatedActor) =>
val actorName = terminatedActor.path.name
if (actorName.startsWith("ChildActor")) {
doSomething()
}
Behaviors.same
In my unit test, I'm trying to do something like this:
val testInbox = TestInbox[ParentActor.Request](name = "ChildActor1")
val testKit = BehaviorTestKit(ParentActor())
testKit.run(Terminated(testInbox.ref))
assert( *** that doSomething() happened *** )
The unit test code doesn't compile. I get this error in the call to testKit.run():
type mismatch; found : akka.actor.typed.Terminated required: ParentActor.Request
I assume that this is because the Terminated message does not inherit from my ParentActor.Request trait.
Based on a below comment, I changed the unit test to:
val testInbox = TestInbox[ParentActor.Request](name = "ChildActor1")
val testKit = BehaviorTestKit(ParentActor())
testKit.signal(Terminated(testInbox.ref))
assert( *** that doSomething() happened *** )
This now compiles, but the call to testKit.signal() now throws a DeathPactException, which the docs say means that the actor is not handling the Terminated message, even though my production code definitely does handle it.
Any idea what is wrong?