From fb8625ce5f43bed321ee40670c7f84d9c66fef69 Mon Sep 17 00:00:00 2001 From: Peter Vlugter Date: Fri, 25 Mar 2011 18:36:12 +1300 Subject: [PATCH] Replace sleep with latch in valueWithin test --- akka-actor/src/test/scala/akka/dispatch/FutureSpec.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/akka-actor/src/test/scala/akka/dispatch/FutureSpec.scala b/akka-actor/src/test/scala/akka/dispatch/FutureSpec.scala index ec46140859..f99f5f5305 100644 --- a/akka-actor/src/test/scala/akka/dispatch/FutureSpec.scala +++ b/akka-actor/src/test/scala/akka/dispatch/FutureSpec.scala @@ -277,14 +277,17 @@ class FutureSpec extends JUnitSuite { } @Test def resultWithinShouldNotThrowExceptions { + val latch = new StandardLatch + val actors = (1 to 10).toList map { _ => actorOf(new Actor { - def receive = { case (add: Int, wait: Int) => Thread.sleep(wait); self reply_? add } + def receive = { case (add: Int, wait: Boolean, latch: StandardLatch) => if (wait) latch.await; self reply_? add } }).start } - def futures = actors.zipWithIndex map { case (actor: ActorRef, idx: Int) => actor.!!![Int]((idx, if(idx >= 5) 5000 else 0 )) } + def futures = actors.zipWithIndex map { case (actor: ActorRef, idx: Int) => actor.!!![Int]((idx, idx >= 5, latch)) } val result = for(f <- futures) yield f.valueWithin(2, TimeUnit.SECONDS) + latch.open val done = result collect { case Some(Right(x)) => x } val undone = result collect { case None => None } val errors = result collect { case Some(Left(t)) => t }