In akka 2.3.9 documentation there is a warning:
Any message send from a
TestProbeto another actor which runs on theCallingThreadDispatcherruns the risk of dead-lock, if that other actor might also send to this probe. The implementation ofTestProbe.watchandTestProbe.unwatchwill also send a message to the watchee, which means that it is dangerous to try watching e.g.TestActorReffrom aTestProbe.
I tried to reproduce the described deadlock situation in test using TestProbe and TestActorRef as both are using CallingThreadDispatcher
class DeadlockTest extends TestKit(ActorSystem()) with FunSuiteLike {
test("deadlock attempt") {
val b = TestProbe()
val a = TestActorRef(new Actor {
override def preStart() = b.ref ! "pre"
def receive = {
case msg =>
sender ! msg
context.stop(self)
}
})
b.watch(a)
b.send(a, "foo")
b.expectMsg("pre")
b.expectMsg("foo")
b.expectTerminated(a)
b.unwatch(a)
}
}
I expected the test to hang but it successfully passed.
Is the warning still relevant and the possibility of deadlock is high or is it outdated?
Aucun commentaire:
Enregistrer un commentaire