From 0ab0b7ef9f65b801edda907a64c208053bc15064 Mon Sep 17 00:00:00 2001 From: Junichi Kato Date: Sat, 24 Apr 2021 22:57:09 +0900 Subject: [PATCH 1/2] refactoring test code --- .../com/chatwork/akka/guard/typed/SABBrokerSpec.scala | 4 ++-- .../com/chatwork/akka/guard/typed/SABExponentialSpec.scala | 4 ++-- .../chatwork/akka/guard/typed/SABReceiveTimeoutSpec.scala | 4 ++-- .../test/scala/com/chatwork/akka/guard/SABBrokerSpec.scala | 4 ++-- .../scala/com/chatwork/akka/guard/SABExponentialSpec.scala | 4 ++-- .../http/typed/ServiceAttackBlockerDirectivesSpec.scala | 4 ++-- .../guard/http/ServiceAttackBlockerDirectivesSpec.scala | 7 +++++++ 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/akka-guard-core-typed/src/test/scala/com/chatwork/akka/guard/typed/SABBrokerSpec.scala b/akka-guard-core-typed/src/test/scala/com/chatwork/akka/guard/typed/SABBrokerSpec.scala index dd5026b..5820749 100644 --- a/akka-guard-core-typed/src/test/scala/com/chatwork/akka/guard/typed/SABBrokerSpec.scala +++ b/akka-guard-core-typed/src/test/scala/com/chatwork/akka/guard/typed/SABBrokerSpec.scala @@ -32,8 +32,8 @@ class SABBrokerSpec implicit override val patienceConfig: PatienceConfig = PatienceConfig( - timeout = scaled(Span(30 * testTimeFactor, Seconds)), - interval = scaled(Span(2 * testTimeFactor, Millis)) + timeout = scaled(Span(3 * testTimeFactor, Seconds)), + interval = scaled(Span(1 * testTimeFactor, Millis)) ) override protected def afterAll(): Unit = { diff --git a/akka-guard-core-typed/src/test/scala/com/chatwork/akka/guard/typed/SABExponentialSpec.scala b/akka-guard-core-typed/src/test/scala/com/chatwork/akka/guard/typed/SABExponentialSpec.scala index 8fd891c..681b2dc 100644 --- a/akka-guard-core-typed/src/test/scala/com/chatwork/akka/guard/typed/SABExponentialSpec.scala +++ b/akka-guard-core-typed/src/test/scala/com/chatwork/akka/guard/typed/SABExponentialSpec.scala @@ -34,8 +34,8 @@ class SABExponentialSpec implicit override val patienceConfig: PatienceConfig = PatienceConfig( - timeout = scaled(Span(30 * testTimeFactor, Seconds)), - interval = scaled(Span(2 * testTimeFactor, Millis)) + timeout = scaled(Span(3 * testTimeFactor, Seconds)), + interval = scaled(Span(1 * testTimeFactor, Millis)) ) override protected def afterAll(): Unit = { diff --git a/akka-guard-core-typed/src/test/scala/com/chatwork/akka/guard/typed/SABReceiveTimeoutSpec.scala b/akka-guard-core-typed/src/test/scala/com/chatwork/akka/guard/typed/SABReceiveTimeoutSpec.scala index 7e9aeda..087a628 100644 --- a/akka-guard-core-typed/src/test/scala/com/chatwork/akka/guard/typed/SABReceiveTimeoutSpec.scala +++ b/akka-guard-core-typed/src/test/scala/com/chatwork/akka/guard/typed/SABReceiveTimeoutSpec.scala @@ -31,8 +31,8 @@ class SABReceiveTimeoutSpec implicit override val patienceConfig: PatienceConfig = PatienceConfig( - timeout = scaled(Span(30 * testTimeFactor, Seconds)), - interval = scaled(Span(2 * testTimeFactor, Millis)) + timeout = scaled(Span(3 * testTimeFactor, Seconds)), + interval = scaled(Span(1 * testTimeFactor, Millis)) ) override protected def afterAll(): Unit = { diff --git a/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABBrokerSpec.scala b/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABBrokerSpec.scala index f9b5a33..bc5b33f 100644 --- a/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABBrokerSpec.scala +++ b/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABBrokerSpec.scala @@ -39,8 +39,8 @@ class SABBrokerSpec implicit override val patienceConfig: PatienceConfig = PatienceConfig( - timeout = scaled(Span(30 * testTimeFactor, Seconds)), - interval = scaled(Span(5 * testTimeFactor, Millis)) + timeout = scaled(Span(3 * testTimeFactor, Seconds)), + interval = scaled(Span(1 * testTimeFactor, Millis)) ) Feature("SABBrokerSpec untyped") { diff --git a/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABExponentialSpec.scala b/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABExponentialSpec.scala index e427219..d27d9f7 100644 --- a/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABExponentialSpec.scala +++ b/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABExponentialSpec.scala @@ -36,8 +36,8 @@ class SABExponentialSpec implicit override val patienceConfig: PatienceConfig = PatienceConfig( - timeout = scaled(Span(30 * testTimeFactor, Seconds)), - interval = scaled(Span(2 * testTimeFactor, Millis)) + timeout = scaled(Span(3 * testTimeFactor, Seconds)), + interval = scaled(Span(1 * testTimeFactor, Millis)) ) "SABExponential untyped" - { diff --git a/akka-guard-http-typed/src/test/scala/com/chatwork/akka/guard/http/typed/ServiceAttackBlockerDirectivesSpec.scala b/akka-guard-http-typed/src/test/scala/com/chatwork/akka/guard/http/typed/ServiceAttackBlockerDirectivesSpec.scala index 9ae9e95..7d0f9e6 100644 --- a/akka-guard-http-typed/src/test/scala/com/chatwork/akka/guard/http/typed/ServiceAttackBlockerDirectivesSpec.scala +++ b/akka-guard-http-typed/src/test/scala/com/chatwork/akka/guard/http/typed/ServiceAttackBlockerDirectivesSpec.scala @@ -35,8 +35,8 @@ class ServiceAttackBlockerDirectivesSpec implicit override val patienceConfig: PatienceConfig = PatienceConfig( - timeout = scaled(Span(30 * testTimeFactor, Seconds)), - interval = scaled(Span(2 * testTimeFactor, Millis)) + timeout = scaled(Span(3 * testTimeFactor, Seconds)), + interval = scaled(Span(1 * testTimeFactor, Millis)) ) override protected def afterAll(): Unit = { diff --git a/akka-guard-http/src/test/scala/com/chatwork/akka/guard/http/ServiceAttackBlockerDirectivesSpec.scala b/akka-guard-http/src/test/scala/com/chatwork/akka/guard/http/ServiceAttackBlockerDirectivesSpec.scala index 71a3d51..a64e8d9 100644 --- a/akka-guard-http/src/test/scala/com/chatwork/akka/guard/http/ServiceAttackBlockerDirectivesSpec.scala +++ b/akka-guard-http/src/test/scala/com/chatwork/akka/guard/http/ServiceAttackBlockerDirectivesSpec.scala @@ -12,6 +12,7 @@ import org.scalatest.concurrent.PatienceConfiguration.Timeout import org.scalatest.concurrent.{ Eventually, ScalaFutures } import org.scalatest.freespec.AnyFreeSpec import org.scalatest.matchers.should.Matchers +import org.scalatest.time.{ Millis, Seconds, Span } import scala.concurrent.duration._ import scala.util.{ Success, Try } @@ -25,6 +26,12 @@ class ServiceAttackBlockerDirectivesSpec val testTimeFactor: Int = sys.env.getOrElse("TEST_TIME_FACTOR", "1").toInt + implicit override val patienceConfig: PatienceConfig = + PatienceConfig( + timeout = scaled(Span(3 * testTimeFactor, Seconds)), + interval = scaled(Span(1 * testTimeFactor, Millis)) + ) + implicit val timeout: AkkaTimeout = AkkaTimeout((4 * testTimeFactor).seconds) val clientId = "id-1" val uri: String => String = prefix => s"/$prefix/$clientId" From 679367969fc363c08d939099c7ad9766e160ab23 Mon Sep 17 00:00:00 2001 From: Junichi Kato Date: Sat, 24 Apr 2021 23:15:34 +0900 Subject: [PATCH 2/2] fix: Don't cache the result of ActorSystem#actorSelection. --- .../src/test/scala/com/chatwork/akka/guard/SABBrokerSpec.scala | 2 +- .../test/scala/com/chatwork/akka/guard/SABExponentialSpec.scala | 2 +- .../scala/com/chatwork/akka/guard/SABReceiveTimeoutSpec.scala | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABBrokerSpec.scala b/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABBrokerSpec.scala index bc5b33f..fbe7fab 100644 --- a/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABBrokerSpec.scala +++ b/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABBrokerSpec.scala @@ -62,7 +62,7 @@ class SABBrokerSpec } val sabBroker: ActorRef = system.actorOf(Props(new SABBroker(config, failedResponse, isFailed)), sabBrokerName1) val messagePath: ActorPath = system / sabBrokerName1 / SABSupervisor.name(messageId) / SABActor.name(messageId) - val messageRef: ActorSelection = system.actorSelection(messagePath) + def messageRef: ActorSelection = system.actorSelection(messagePath) When("Long input") Then("return success message") diff --git a/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABExponentialSpec.scala b/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABExponentialSpec.scala index d27d9f7..d0860a5 100644 --- a/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABExponentialSpec.scala +++ b/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABExponentialSpec.scala @@ -100,7 +100,7 @@ class SABExponentialSpec sabBrokerName1 ) val messagePath: ActorPath = system / sabBrokerName1 / SABSupervisor.name(messageId) / SABActor.name(messageId) - val messageRef: ActorSelection = system.actorSelection(messagePath) + def messageRef: ActorSelection = system.actorSelection(messagePath) val message1 = SABMessage(messageId, "A" * 50, handler) (sabBroker ? message1).mapTo[String].futureValue shouldBe successMessage diff --git a/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABReceiveTimeoutSpec.scala b/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABReceiveTimeoutSpec.scala index 3bb41a9..67d4db0 100644 --- a/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABReceiveTimeoutSpec.scala +++ b/akka-guard-core/src/test/scala/com/chatwork/akka/guard/SABReceiveTimeoutSpec.scala @@ -65,7 +65,7 @@ class SABReceiveTimeoutSpec } val sabBroker: ActorRef = system.actorOf(Props(new SABBroker(config, failedResponse, isFailed)), sabBrokerName1) val messagePath: ActorPath = system / sabBrokerName1 / SABSupervisor.name(messageId) / SABActor.name(messageId) - val messageRef: ActorSelection = system.actorSelection(messagePath) + def messageRef: ActorSelection = system.actorSelection(messagePath) val message1 = SABMessage(messageId, "A" * BoundaryLength, handler) (sabBroker ? message1).mapTo[String].futureValue shouldBe successMessage