Actor name is not unique after termination when running from unit tests

1,576 views
Skip to first unread message

Piotr Droździel

unread,
Apr 27, 2017, 11:06:49 AM4/27/17
to Akka User List
Hello,
Akka docs say:

Warning

Keep in mind that an actor stopping and its name being deregistered are separate events which happen asynchronously from each other. Therefore it may be that you will find the name still in use after gracefulStop() returned. In order to guarantee proper deregistration, only reuse names from within a supervisor you control and only in response to a Terminated message, i.e. not for top-level actors.


But when testing one of the actors I get InvalidActorNameException even after expectTerminated was successful. This is the test:


"stop self when finished" in {
 val fetcher
= system.actorOf(EventFetcherActor.props(eventId), "name1")

 watch
(fetcher)
 
// interact with the actor, it will call context.stop(self) after interaction

 expectTerminated
(fetcher)

 system
.actorOf(EventFetcherActor.props(eventId), "name1") //Exception thrown
}

90% of times I run it, the test passes. But what is the reason of failures? Can it be related to the fact that it's unit test? 

This is exception message I get:
actor name [name1] is not unique!
akka.actor.InvalidActorNameException: actor name [name1] is not unique!
at akka.actor.dungeon.ChildrenContainer$NormalChildrenContainer.reserve(ChildrenContainer.scala:129)
at akka.actor.dungeon.Children$class.reserveChild(Children.scala:130)
at akka.actor.ActorCell.reserveChild(ActorCell.scala:374)
at akka.actor.dungeon.Children$class.makeChild(Children.scala:268)
at akka.actor.dungeon.Children$class.attachChild(Children.scala:46)

Viktor Klang

unread,
Apr 27, 2017, 11:17:39 AM4/27/17
to Akka User List
Hi Piotr,

the test thread having observed the termination does not mean that the user guardian (/user) has observed it.

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscribe@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Cheers,

Konrad Malawski

unread,
Apr 27, 2017, 11:19:00 AM4/27/17
to akka...@googlegroups.com, Viktor Klang
In other words, only the parent of the stopped actor can safely "aha! I've seen it stopped, so I'll start a new one with the same name".
This is documented behavior in the Actor docs :)

-- 
Konrad `ktoso` Malawski
Akka @ Lightbend
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.

Patrik Nordwall

unread,
Apr 29, 2017, 3:47:38 PM4/29/17
to Viktor Klang, akka...@googlegroups.com
From a test like that I'd use unique names for top level actors, and if that is not possible I'd use awaitAssert to retry creating the actor until the name is free.

/Patrik




--
Cheers,
Reply all
Reply to author
Forward
0 new messages