scala - Does ActorRef obtained via system.actorOf equal to self inside this actor? -


i've designed actor should send its' actorref actor on prestart:

class myactor(notifier: actorref) extends actor {   override def prestart(): unit = {     notifier ! register(self)   }   ... }  case class register(actor: actorref) 

then i've written specification actor:

class myactorspec extends testkit(actorsystem("myactorspec"))                   implicitsender                    wordspeclike                    matchers                    beforeandafterall {    "myactor" should {      val notifier = testprobe()      "register in notifier" in {          val myactor = system.actorof(props(classof[myactor], notifier.ref))          notifier.expectmsg(register(myactor))      }   } } 

when run test, fails following message: assertion failed: expected register(actor[akka://myactorspec/user/$b#1849780829]), found register(actor[akka://myactorspec/user/$a#1143150267])

so, seems actorref obtained via self inside myactor not equal actorref obtained via system.actorof in test. suggestions?

the following code working fine me (the test passes):

class myactor(notifier: actorref) extends actor {   override def prestart(): unit = {     notifier ! register(self)   }    override def receive: receive = {     case _ =>   } }  case class register(actor: actorref)  class myactorspec extends testkit(actorsystem("myactorspec")) implicitsender wordspeclike matchers beforeandafterall {   "myactor" should {     val notifier = testprobe()     "register in notifier" in {       val myactor = system.actorof(props(new myactor(notifier.ref)))       notifier.expectmsg(register(myactor))     }   } } 

Comments