I had the same issue where unstashAll() was not working in TestActorRef. I managed to get my tests working by changing the dispatcher the TestActor used to the default-dispatcher. I guess this loses the benefits of using CallingThreadDispatcher as highlighted in the docs <http://doc.akka.io/docs/akka/snapshot/scala/testing.html#Benefits>, but at least my tests pass now!
http://stackoverflow.com/a/34308851/936869 On Monday, March 2, 2015 at 1:31:15 PM UTC, Sam Halliday wrote: > > Grr, so it seems that TestActorRef really is incompatible with Stash. > > http://stackoverflow.com/questions/18335127 > > This is a real shame. > > On Monday, 2 March 2015 12:35:22 UTC, Sam Halliday wrote: >> >> Wow, I think I figured this out... and it's quite scary. >> >> Stash needs an unbounded mailbox. I didn't quite pick up on this because >> somebody in our team had made the default dispatcher an unbounded mailbox >> at some point and now there is no going back. >> >> Then when I wanted to use TestActorRef, it blew up when I tried to create >> my actor because it uses an unbounded mailbox, so I had to give it a >> bounded mailbox to pass the test. >> >> *That seems to have disabled Stash without any warning* for this Actor. >> >> There seems to be several funky things going on here: >> >> 1. why doesn't initialisation blow up when I have an Actor with Stash >> used with an unbounded mailbox? >> 2. why is TestActorRef enforcing that unbounded mailboxes cannot be used? >> --- doesn't this mean that TestActorRef cannot be used to test an Actor >> with Stash? >> >> >> >> On Monday, 2 March 2015 12:13:40 UTC, Sam Halliday wrote: >>> >>> Looks like I'm seeing the same thing as >>> >>> https://groups.google.com/d/msg/akka-user/Vb2dQtZX6DI/lZtEvg8DwkkJ >>> >>> but I see the "Awaken" message immediately ... which means the >>> `unstashAll` simply hasn't added anything onto the actor queue (until after >>> the actor dies?) >>> >>> On Monday, 2 March 2015 12:05:52 UTC, Sam Halliday wrote: >>>> >>>> Hi all, >>>> >>>> I have an Actor which is using Stash and is working through two >>>> different Receive behaviours with context.become. Messages are stashed >>>> until we're ready to receive them. >>>> >>>> I've used context.become(), stash() and unstashAll() several times, so >>>> I'm pretty familiar with them, but I'm seeing a bizarre behaviour in this >>>> Actor and I was wondering if I'm using it wrong in a subtle way. >>>> >>>> In the part of the Actor code that is causing the problem, I am doing >>>> this: >>>> >>>> def catchUp: Receive = LoggingReceive { >>>> case item: PublishItem => >>>> stash() >>>> case event: Event => >>>> context.become(republishing) >>>> unstashAll() >>>> } >>>> >>>> def republishing: Receive = LoggingReceive { >>>> case event: PublishItem => >>>> downstream ! event >>>> case e: Event => // ignore leftover messages from the dying loader >>>> } >>>> >>>> >>>> In my test I send a bunch of PublishItem's, then send the Event that >>>> changes the behaviour. Then I assert that 'downstream' receives all the >>>> backlogged PublishItems. >>>> >>>> However, what I'm actually seeing are "handled event"s for the >>>> PublishItem and Event into the catchUp behaviour. Then I see the test >>>> timing out waiting for the PublishItem to appear in downstream and then >>>> (the really weird bit) the actor is stopped and AFTER this actor stops, >>>> all >>>> the PublishItems show up in the dead letters mailbox. >>>> >>>> Any ideas? >>>> >>>> As a workaround, I am managing my own stash as a Queue, but this sucks >>>> because my stashed messages arrive after other messages that are already >>>> queued and that breaks the assumed logic of the whole actor. >>>> >>>> I'm using akka 2.3.9 on scala 2.11.5 >>>> >>>> Best regards, >>>> Sam >>>> >>>> -- >>>>>>>>>> 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
