fix SchedulerSpec and ActorTimeoutSpec
This commit is contained in:
parent
e5003c9795
commit
035a1d28a0
2 changed files with 18 additions and 10 deletions
|
|
@ -13,6 +13,7 @@ import akka.pattern.{ ask, AskTimeoutException }
|
|||
class ActorTimeoutSpec extends AkkaSpec {
|
||||
|
||||
val testTimeout = 200.millis.dilated
|
||||
val leeway = 500.millis.dilated
|
||||
|
||||
"An Actor-based Future" must {
|
||||
|
||||
|
|
@ -20,13 +21,13 @@ class ActorTimeoutSpec extends AkkaSpec {
|
|||
implicit val timeout = Timeout(testTimeout)
|
||||
val echo = system.actorOf(Props.empty)
|
||||
val f = (echo ? "hallo")
|
||||
intercept[AskTimeoutException] { Await.result(f, testTimeout * 2) }
|
||||
intercept[AskTimeoutException] { Await.result(f, testTimeout + leeway) }
|
||||
}
|
||||
|
||||
"use explicitly supplied timeout" in {
|
||||
val echo = system.actorOf(Props.empty)
|
||||
val f = echo.?("hallo")(testTimeout)
|
||||
intercept[AskTimeoutException] { Await.result(f, testTimeout * 2) }
|
||||
intercept[AskTimeoutException] { Await.result(f, testTimeout + leeway) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class SchedulerSpec extends AkkaSpec with BeforeAndAfterEach with DefaultTimeout
|
|||
collectCancellable(system.scheduler.schedule(0 milliseconds, 50 milliseconds, tickActor, Tick))
|
||||
|
||||
// after max 1 second it should be executed at least the 3 times already
|
||||
assert(countDownLatch.await(1, TimeUnit.SECONDS))
|
||||
assert(countDownLatch.await(2, TimeUnit.SECONDS))
|
||||
|
||||
val countDownLatch2 = new CountDownLatch(3)
|
||||
|
||||
|
|
@ -44,13 +44,20 @@ class SchedulerSpec extends AkkaSpec with BeforeAndAfterEach with DefaultTimeout
|
|||
}
|
||||
|
||||
"should stop continuous scheduling if the receiving actor has been terminated" in {
|
||||
val actor = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case x => testActor ! x
|
||||
}
|
||||
}))
|
||||
|
||||
// run immediately and then every 100 milliseconds
|
||||
collectCancellable(system.scheduler.schedule(0 milliseconds, 100 milliseconds, testActor, "msg"))
|
||||
collectCancellable(system.scheduler.schedule(0 milliseconds, 100 milliseconds, actor, "msg"))
|
||||
|
||||
// stop the actor and, hence, the continuous messaging from happening
|
||||
testActor ! PoisonPill
|
||||
actor ! PoisonPill
|
||||
|
||||
expectNoMsg(500 milliseconds)
|
||||
expectMsg("msg")
|
||||
expectNoMsg(1 second)
|
||||
}
|
||||
|
||||
"schedule once" in {
|
||||
|
|
@ -69,7 +76,7 @@ class SchedulerSpec extends AkkaSpec with BeforeAndAfterEach with DefaultTimeout
|
|||
countDownLatch.getCount must be(3)
|
||||
|
||||
// after 1 second the wait should fail
|
||||
assert(countDownLatch.await(1, TimeUnit.SECONDS) == false)
|
||||
assert(countDownLatch.await(2, TimeUnit.SECONDS) == false)
|
||||
// should still be 1 left
|
||||
countDownLatch.getCount must be(1)
|
||||
}
|
||||
|
|
@ -93,7 +100,7 @@ class SchedulerSpec extends AkkaSpec with BeforeAndAfterEach with DefaultTimeout
|
|||
assert(ticks.await(3, TimeUnit.SECONDS) == false) //No counting down should've been made
|
||||
}
|
||||
|
||||
"be cancellable during initial delay" in {
|
||||
"be cancellable during initial delay" taggedAs TimingTest in {
|
||||
val ticks = new AtomicInteger
|
||||
|
||||
val initialDelay = 200.milliseconds.dilated
|
||||
|
|
@ -108,7 +115,7 @@ class SchedulerSpec extends AkkaSpec with BeforeAndAfterEach with DefaultTimeout
|
|||
ticks.get must be(0)
|
||||
}
|
||||
|
||||
"be cancellable after initial delay" in {
|
||||
"be cancellable after initial delay" taggedAs TimingTest in {
|
||||
val ticks = new AtomicInteger
|
||||
|
||||
val initialDelay = 20.milliseconds.dilated
|
||||
|
|
@ -179,7 +186,7 @@ class SchedulerSpec extends AkkaSpec with BeforeAndAfterEach with DefaultTimeout
|
|||
Await.ready(ticks, 3 seconds)
|
||||
}
|
||||
|
||||
"schedule with different initial delay and frequency" in {
|
||||
"schedule with different initial delay and frequency" taggedAs TimingTest in {
|
||||
val ticks = new TestLatch(3)
|
||||
|
||||
case object Msg
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue