How to test an actor does not stop in Akka

I'm trying to check if an actor was completed or not, I know there is a way to check if it was completed using TestProbe expectTerminated

http://doc.akka.io/docs/akka/2.4.16/scala/testing.html#Watching_Other_Actors_from_Probes

But is there a way to check the opposite?

Thank:)

Update

In my scenario, I have a custom actor that has one or more child actors, and it will stop when all its children are disconnected (completed).

The behavior works fine, but my problem is that I can only test the script in which it has no children, and finish it myself. I cannot find the right statement to verify that it is not completed if he still has children.

Here's a simplified test version:

"Terminates itself if there are no connected clients" in {
  val userActor = system.ActorOf(UserActor.props())

  userActor ! UserActor.ClientDisconnected()

  val deathWatch = TestProbe()
  deathWatch.watch(userActor)
  deathWatch.expectTerminated(userActor, timeoutDuration)
}

"Not Terminates itself when there are still other clients connected" in {
  val userActor = system.ActorOf(UserActor.props())

  // Connecting a client
  userActor ! UserActor.ClientConnected(sessionId, accessToken)

  userActor ! UserActor.ClientDisconnected()

  // How can I test that userActor is not terminated?
}
+4
1

-, - :

  import scala.concurrent.duration._
  import akka.testkit._

  def expectNoTerminated(target: ActorRef, max: FiniteDuration) {
    val o = receiveOne(max.dilated)

    if (o ne null)
      assert(o != Terminated(target), s"received Terminated message $o")
  }

, , , Terminated, , .

+1

Source: https://habr.com/ru/post/1667873/


All Articles