From bb5ab968dbc372c4554aa634a8ac1089b3dcad2e Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Mon, 10 Sep 2012 16:20:38 +0200 Subject: [PATCH] Make RoutingSpec more robust, see #2484 --- .../test/scala/akka/routing/RoutingSpec.scala | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala b/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala index b7000779af..782f4fb399 100644 --- a/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala @@ -102,8 +102,6 @@ class RoutingSpec extends AkkaSpec(RoutingSpec.config) with DefaultTimeout with } "be able to send their routees" in { - val doneLatch = new TestLatch(1) - class TheActor extends Actor { val routee1 = context.actorOf(Props[TestActor], "routee1") val routee2 = context.actorOf(Props[TestActor], "routee2") @@ -114,19 +112,18 @@ class RoutingSpec extends AkkaSpec(RoutingSpec.config) with DefaultTimeout with within = 5 seconds))) def receive = { - case RouterRoutees(iterable) ⇒ - iterable.exists(_.path.name == "routee1") must be(true) - iterable.exists(_.path.name == "routee2") must be(true) - iterable.exists(_.path.name == "routee3") must be(true) - doneLatch.countDown() - case "doIt" ⇒ - router ! CurrentRoutees + case "doIt" ⇒ router ! CurrentRoutees + case routees: RouterRoutees ⇒ testActor forward routees } } val theActor = system.actorOf(Props(new TheActor), "theActor") theActor ! "doIt" - Await.ready(doneLatch, remaining) + val routees = expectMsgPF() { + case RouterRoutees(routees) ⇒ routees.toSet + } + + routees.map(_.path.name) must be(Set("routee1", "routee2", "routee3")) } "use configured nr-of-instances when FromConfig" in { @@ -226,14 +223,9 @@ class RoutingSpec extends AkkaSpec(RoutingSpec.config) with DefaultTimeout with } "send message to connection" in { - val doneLatch = new TestLatch(1) - - val counter = new AtomicInteger(0) - class Actor1 extends Actor { def receive = { - case "end" ⇒ doneLatch.countDown() - case _ ⇒ counter.incrementAndGet + case msg ⇒ testActor forward msg } } @@ -241,9 +233,8 @@ class RoutingSpec extends AkkaSpec(RoutingSpec.config) with DefaultTimeout with routedActor ! "hello" routedActor ! "end" - Await.ready(doneLatch, remaining) - - counter.get must be(1) + expectMsg("hello") + expectMsg("end") } }