From 7695bb0697f2856df4075b6ce9fd2b25d8ea8e36 Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Wed, 5 Dec 2012 12:17:39 +0100 Subject: [PATCH] Don't use top level actor in PriorityDispatcherSpec, see #2745 * The actor was a top level, i.e. RepointableActorRef. Messages sent to self from constructor could be queued in UnstartedCell, and then sent to the real PriorityQueue later, processed immediately without the ordering taking place first. --- .../dispatch/PriorityDispatcherSpec.scala | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala b/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala index 4dad37c1be..4e76c5bea6 100644 --- a/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala @@ -51,19 +51,28 @@ class PriorityDispatcherSpec extends AkkaSpec(PriorityDispatcherSpec.config) wit def testOrdering(dispatcherKey: String) { val msgs = (1 to 100) toList + // It's important that the actor under test is not a top level actor + // with RepointableActorRef, since messages might be queued in + // UnstartedCell and the sent to the PriorityQueue and consumed immediately + // without the ordering taking place. val actor = system.actorOf(Props(new Actor { + context.actorOf(Props(new Actor { - val acc = scala.collection.mutable.ListBuffer[Int]() + val acc = scala.collection.mutable.ListBuffer[Int]() - scala.util.Random.shuffle(msgs) foreach { m ⇒ self ! m } + scala.util.Random.shuffle(msgs) foreach { m ⇒ self ! m } - self.tell('Result, testActor) + self.tell('Result, testActor) - def receive = { - case i: Int ⇒ acc += i - case 'Result ⇒ sender ! acc.toList - } - }).withDispatcher(dispatcherKey)) + def receive = { + case i: Int ⇒ acc += i + case 'Result ⇒ sender ! acc.toList + } + }).withDispatcher(dispatcherKey)) + + def receive = Actor.emptyBehavior + + })) expectMsgType[List[_]] must be === msgs }