adding AtLeastOnceDelivery trait broke my test

59 views
Skip to first unread message

Giampaolo

unread,
May 27, 2015, 5:17:53 AM5/27/15
to akka...@googlegroups.com
Hi to all,
I have something strange that I cannot understand.

I have this test that worked very well

 "give online status NeverLogged for never logged user" in new WithUsersData() {
      val auth = createAndAuthenticateUser
      val user1 = auth._1
      val sid1 = auth._2

      val tp1 = TestProbe()

      val dispatcher1 = TestActorRef(DispatcherActor.props(tp1.ref))

      dispatcher1 ! Presence("rid_test2", sid1)
      tp1.expectMsgType[Notification.Presence]
}

Then I added AtLeastOnceDelivery trait to the DispatcherActor for messages it needs to send to other actors. Keep in mind that in my test, dispatcher1 is receiving a message, not sending one. It broke my tests.
It seems to me that dispatcher1 is not ready when I fire the Presence message, since I see no logging from that actor. However if I change the code this way:

for(i <- 0 to 0){
  dispatcher1 ! Presence("rid_test2", sid1)
}

or in  this way
Thread.sleep(50)
dispatcher1 ! Presence("rid_test2", sid1)

Test is successful. Could you give me some advice in investigating this problem?
Thank you in advance for your precious time.

Giampaolo



Akka Team

unread,
May 29, 2015, 9:37:00 AM5/29/15
to Akka User List
Hi there,
in general we do not encourage the use of TestActorRef - the way it works is by forcing the CallingThreadDispatcher, which does not mix well with Actors which need to perform work in the background.
For example PersistentActors need to execute recovery etc (if you're using AtLeastOnceDelivery it means you must be using Persistence already).

Summing up, the solution is to not use TestActorRef.
In the tests you show you are not using any of TestActorRefs features anyway, so removing should be painless indeed :-)


Happy hakking!

--
>>>>>>>>>> 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+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Akka Team
Typesafe - Reactive apps on the JVM
Blog: letitcrash.com
Twitter: @akkateam

Giampaolo

unread,
Jun 5, 2015, 4:20:23 AM6/5/15
to akka...@googlegroups.com
Many thanks Akka Team for the reply. 
Do you think that this info should be added to TestKit doc to avoid this mistake for Akka newbies like me?

giampaolo

Akka Team

unread,
Jun 7, 2015, 7:56:02 AM6/7/15
to Akka User List
Hi,



On Fri, Jun 5, 2015 at 10:20 AM, Giampaolo <giampaolo...@gmail.com> wrote:
Many thanks Akka Team for the reply. 
Do you think that this info should be added to TestKit doc to avoid this mistake for Akka newbies like me?

Yes, I think so. Can you file a ticket for this?

-Endre

Giampaolo

unread,
Jul 23, 2015, 9:13:39 AM7/23/15
to Akka User List, akka.o...@gmail.com
Sorry for the delay Endre. It's been a while I do not read this user list.

It's my very first one, hope I did it well.

giampaolo
Reply all
Reply to author
Forward
0 new messages