Replace sleep with latch in valueWithin test

This commit is contained in:
Peter Vlugter 2011-03-25 18:36:12 +13:00
parent d8c07d05e8
commit fb8625ce5f

View file

@ -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 }