From 697f7a0e08b9a93d6568712ede87d45c7d533546 Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Fri, 1 Oct 2021 15:41:17 +0200 Subject: [PATCH] dilate TestKit shutdownActorSystem (#30685) * rather many "Failed to stop [] within [10 seconds]" in CI --- .../sharding/typed/ReplicatedShardingSpec.scala | 10 ++-------- .../typed/scaladsl/ClusterShardingSpec.scala | 2 +- .../cluster/typed/RemoteDeployNotAllowedSpec.scala | 4 +--- .../src/main/scala/akka/testkit/TestKit.scala | 14 ++++++++++---- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/ReplicatedShardingSpec.scala b/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/ReplicatedShardingSpec.scala index 9805571040..76aab53e72 100644 --- a/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/ReplicatedShardingSpec.scala +++ b/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/ReplicatedShardingSpec.scala @@ -234,10 +234,7 @@ abstract class ReplicatedShardingSpec(replicationType: ReplicationType, configA: override protected def afterAll(): Unit = { super.afterAll() - ActorTestKit.shutdown( - system2, - testKitSettings.DefaultActorSystemShutdownTimeout, - testKitSettings.ThrowOnShutdownTimeout) + ActorTestKit.shutdown(system2) } "Replicated sharding" should { @@ -294,10 +291,7 @@ abstract class ReplicatedShardingSpec(replicationType: ReplicationType, configA: // logging to diagnose // https://github.com/akka/akka/issues/30501 and // https://github.com/akka/akka/issues/30502 - ActorTestKit.shutdown( - system2, - testKitSettings.DefaultActorSystemShutdownTimeout, - testKitSettings.ThrowOnShutdownTimeout) + ActorTestKit.shutdown(system2) } } diff --git a/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/scaladsl/ClusterShardingSpec.scala b/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/scaladsl/ClusterShardingSpec.scala index be21d3e3f4..ff7b8c90d7 100644 --- a/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/scaladsl/ClusterShardingSpec.scala +++ b/akka-cluster-sharding-typed/src/test/scala/akka/cluster/sharding/typed/scaladsl/ClusterShardingSpec.scala @@ -125,7 +125,7 @@ class ClusterShardingSpec val sharding2 = ClusterSharding(system2) override def afterAll(): Unit = { - ActorTestKit.shutdown(system2, 5.seconds) + ActorTestKit.shutdown(system2) super.afterAll() } diff --git a/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteDeployNotAllowedSpec.scala b/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteDeployNotAllowedSpec.scala index af634564a6..dd972b82ae 100644 --- a/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteDeployNotAllowedSpec.scala +++ b/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteDeployNotAllowedSpec.scala @@ -4,8 +4,6 @@ package akka.cluster.typed -import scala.concurrent.duration._ - import com.typesafe.config.ConfigFactory import org.scalatest.wordspec.AnyWordSpecLike @@ -103,7 +101,7 @@ class RemoteDeployNotAllowedSpec system2 ! SpawnAnonymous probe.expectMessageType[Exception].getMessage should ===("Remote deployment not allowed for typed actors") } finally { - ActorTestKit.shutdown(system2, 5.seconds) + ActorTestKit.shutdown(system2) } } } diff --git a/akka-testkit/src/main/scala/akka/testkit/TestKit.scala b/akka-testkit/src/main/scala/akka/testkit/TestKit.scala index 347fda0c4d..943d28a80b 100644 --- a/akka-testkit/src/main/scala/akka/testkit/TestKit.scala +++ b/akka-testkit/src/main/scala/akka/testkit/TestKit.scala @@ -878,7 +878,7 @@ trait TestKitBase { */ def shutdown( actorSystem: ActorSystem = system, - duration: Duration = 10.seconds.dilated.min(10.seconds), + duration: Duration = Duration.Undefined, verifySystemShutdown: Boolean = false): Unit = { TestKit.shutdownActorSystem(actorSystem, duration, verifySystemShutdown) } @@ -1015,19 +1015,25 @@ object TestKit { * Shut down an actor system and wait for termination. * On failure debug output will be logged about the remaining actors in the system. * + * The `duration` is dilated by the timefactor. + * * If verifySystemShutdown is true, then an exception will be thrown on failure. */ def shutdownActorSystem( actorSystem: ActorSystem, - duration: Duration = 10.seconds, + duration: Duration = Duration.Undefined, verifySystemShutdown: Boolean = false): Unit = { + val d = duration match { + case f: FiniteDuration => f.dilated(actorSystem) + case _ => 10.seconds.dilated(actorSystem).min(10.seconds) + } actorSystem.terminate() - try Await.ready(actorSystem.whenTerminated, duration) + try Await.ready(actorSystem.whenTerminated, d) catch { case _: TimeoutException => val msg = "Failed to stop [%s] within [%s] \n%s".format( actorSystem.name, - duration, + d, actorSystem.asInstanceOf[ActorSystemImpl].printTree) if (verifySystemShutdown) throw new RuntimeException(msg) else println(msg)