From dcf61a83c0f5fb02f14f4f20580dbf6146de55d7 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Wed, 22 May 2019 16:38:10 +0200 Subject: [PATCH] More specific test timing expectations (#26918) * More specific test timing expectations (#22098) * Add another retry to justify the wider expectMsg margin --- .../BackoffOnRestartSupervisorSpec.scala | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/akka-actor-tests/src/test/scala/akka/pattern/BackoffOnRestartSupervisorSpec.scala b/akka-actor-tests/src/test/scala/akka/pattern/BackoffOnRestartSupervisorSpec.scala index 54b594f03c..1c5b3b8523 100644 --- a/akka-actor-tests/src/test/scala/akka/pattern/BackoffOnRestartSupervisorSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/pattern/BackoffOnRestartSupervisorSpec.scala @@ -58,7 +58,7 @@ class BackoffOnRestartSupervisorSpec extends AkkaSpec with ImplicitSender { def supervisorProps(probeRef: ActorRef) = { val options = Backoff .onFailure(TestActor.props(probeRef), "someChildName", 200 millis, 10 seconds, 0.0, maxNrOfRetries = -1) - .withSupervisorStrategy(OneForOneStrategy(maxNrOfRetries = 4, withinTimeRange = 30 seconds) { + .withSupervisorStrategy(OneForOneStrategy(maxNrOfRetries = 5, withinTimeRange = 30 seconds) { case _: TestActor.StoppingException => SupervisorStrategy.Stop }) BackoffSupervisor.props(options) @@ -89,19 +89,25 @@ class BackoffOnRestartSupervisorSpec extends AkkaSpec with ImplicitSender { "restart the child with an exponential back off" in new Setup { filterException[TestActor.TestException] { // Exponential back off restart test - probe.within(1.4 seconds, 2 seconds) { - supervisor ! "THROW" - // numRestart = 0 ~ 200 millis - probe.expectMsg(300 millis, "STARTED") + supervisor ! "THROW" + // numRestart = 0: expected delay ~200 millis + probe.expectNoMessage(200 millis) + probe.expectMsg(250 millis, "STARTED") - supervisor ! "THROW" - // numRestart = 1 ~ 400 millis - probe.expectMsg(500 millis, "STARTED") + supervisor ! "THROW" + // numRestart = 1: expected delay ~400 millis + probe.expectNoMessage(400 millis) + probe.expectMsg(250 millis, "STARTED") - supervisor ! "THROW" - // numRestart = 2 ~ 800 millis - probe.expectMsg(900 millis, "STARTED") - } + supervisor ! "THROW" + // numRestart = 2: expected delay ~800 millis + probe.expectNoMessage(800 millis) + probe.expectMsg(250 millis, "STARTED") + + supervisor ! "THROW" + // numRestart = 3: expected delay ~1600 millis + probe.expectNoMessage(1600 millis) + probe.expectMsg(250 millis, "STARTED") // Verify that we only have one child at this point by selecting all the children // under the supervisor and broadcasting to them. @@ -192,10 +198,10 @@ class BackoffOnRestartSupervisorSpec extends AkkaSpec with ImplicitSender { "respect maxNrOfRetries property of OneForOneStrategy" in new Setup { filterException[TestActor.TestException] { probe.watch(supervisor) - // Have the child throw an exception 5 times, which is more than the max restarts allowed. - for (i <- 1 to 5) { + // Have the child throw an exception 6 times, which is more than the max restarts allowed. + for (i <- 1 to 6) { supervisor ! "THROW" - if (i < 5) { + if (i < 6) { // Since we should've died on this throw, don't expect to be started. // We're not testing timing, so set a reasonably high timeout. probe.expectMsg(4 seconds, "STARTED")