From cdcc098e0173082658362776ada8fd7c703c8a84 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Tue, 18 Dec 2012 14:31:18 +0100 Subject: [PATCH] Rewriting the fix to PatternSpec --- .../src/test/scala/akka/pattern/PatternSpec.scala | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/akka-actor-tests/src/test/scala/akka/pattern/PatternSpec.scala b/akka-actor-tests/src/test/scala/akka/pattern/PatternSpec.scala index 0adfa56c4c..0e4333e04e 100644 --- a/akka-actor-tests/src/test/scala/akka/pattern/PatternSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/pattern/PatternSpec.scala @@ -6,7 +6,7 @@ package akka.pattern import language.postfixOps -import akka.testkit.AkkaSpec +import akka.testkit.{ TestLatch, AkkaSpec } import akka.actor.{ Props, Actor } import java.util.concurrent.TimeoutException import scala.concurrent.{ Future, Promise, Await } @@ -16,7 +16,8 @@ object PatternSpec { case class Work(duration: Duration) class TargetActor extends Actor { def receive = { - case Work(duration) ⇒ Thread.sleep(duration.toMillis) + case (testLatch: TestLatch, duration: FiniteDuration) ⇒ + Await.ready(testLatch, duration) } } } @@ -40,10 +41,12 @@ class PatternSpec extends AkkaSpec { Await.ready(gracefulStop(target, 1 millis), 1 second) } - "complete Future with TimeoutException when actor not terminated within timeout" in { + "complete Future with AskTimeoutException when actor not terminated within timeout" in { val target = system.actorOf(Props[TargetActor]) - target ! Work(250 millis) - intercept[TimeoutException] { Await.result(gracefulStop(target, 10 millis), 200 millis) } + val latch = TestLatch() + target ! (latch, remaining) + intercept[AskTimeoutException] { Await.result(gracefulStop(target, 500 millis), remaining) } + latch.open() } }