mercredi 22 avril 2015

Is TestActorRef deadlock possibility still relevant?

In akka 2.3.9 documentation there is a warning:

Any message send from a TestProbe to another actor which runs on the CallingThreadDispatcher runs the risk of dead-lock, if that other actor might also send to this probe. The implementation of TestProbe.watch and TestProbe.unwatch will also send a message to the watchee, which means that it is dangerous to try watching e.g. TestActorRef from a TestProbe.

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