diff --git a/akka-actor-testkit-typed/src/main/mima-filters/2.6.15.backwards.excludes/excess-checking.excludes b/akka-actor-testkit-typed/src/main/mima-filters/2.6.15.backwards.excludes/excess-checking.excludes new file mode 100644 index 0000000000..51a0d83c08 --- /dev/null +++ b/akka-actor-testkit-typed/src/main/mima-filters/2.6.15.backwards.excludes/excess-checking.excludes @@ -0,0 +1,6 @@ +# Extra methods on interfaces not for user extension: +ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.actor.testkit.typed.javadsl.LoggingTestKit.withCheckExcess") +ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.actor.testkit.typed.scaladsl.LoggingTestKit.withCheckExcess") + +# Impl +ProblemFilters.exclude[Problem]("akka.actor.testkit.typed.internal.LoggingTestKitImpl.*") diff --git a/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/internal/LoggingTestKitImpl.scala b/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/internal/LoggingTestKitImpl.scala index 273272ea38..83f5b1eb7b 100644 --- a/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/internal/LoggingTestKitImpl.scala +++ b/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/internal/LoggingTestKitImpl.scala @@ -24,7 +24,8 @@ import akka.testkit.TestKit * INTERNAL API */ @InternalApi private[akka] object LoggingTestKitImpl { - def empty: LoggingTestKitImpl = new LoggingTestKitImpl(1, None, None, None, None, None, None, Map.empty, None) + def empty: LoggingTestKitImpl = + new LoggingTestKitImpl(1, None, None, None, None, None, None, Map.empty, checkExcess = true, None) } /** @@ -39,6 +40,7 @@ import akka.testkit.TestKit messageRegex: Option[Regex], cause: Option[Class[_ <: Throwable]], mdc: Map[String, String], + checkExcess: Boolean, custom: Option[Function[LoggingEvent, Boolean]]) extends javadsl.LoggingTestKit with scaladsl.LoggingTestKit { @@ -92,14 +94,14 @@ import akka.testkit.TestKit try { val result = code - // wait some more when occurrences=0 to find asynchronous exceess messages + // wait some more when occurrences=0 to find asynchronous excess messages if (occurrences == 0) awaitNoExcess(settings.ExpectNoMessageDefaultTimeout) if (!awaitDone(settings.FilterLeeway)) if (todo > 0) throw new AssertionError(s"Timeout (${settings.FilterLeeway}) waiting for $todo messages on $this.") - else + else if (checkExcess) throw new AssertionError(s"Received ${-todo} excess messages on $this.") result } finally { @@ -152,6 +154,9 @@ import akka.testkit.TestKit withMdc(newMdc.asScala.toMap) } + override def withCheckExcess(check: Boolean): LoggingTestKitImpl = + copy(checkExcess = check) + override def withCustom(newCustom: Function[LoggingEvent, Boolean]): LoggingTestKitImpl = copy(custom = Option(newCustom)) diff --git a/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/javadsl/LoggingTestKit.scala b/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/javadsl/LoggingTestKit.scala index dc0fddebc5..d1c33efc16 100644 --- a/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/javadsl/LoggingTestKit.scala +++ b/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/javadsl/LoggingTestKit.scala @@ -76,6 +76,11 @@ import akka.annotation.DoNotInherit */ def withMdc(newMdc: java.util.Map[String, String]): LoggingTestKit + /** + * After matching the expected number of hits, check for excess messages + */ + def withCheckExcess(check: Boolean): LoggingTestKit + /** * Matching events for which the supplied function returns `true`. */ diff --git a/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/scaladsl/LoggingTestKit.scala b/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/scaladsl/LoggingTestKit.scala index 71b5849e04..abda6f888e 100644 --- a/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/scaladsl/LoggingTestKit.scala +++ b/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/scaladsl/LoggingTestKit.scala @@ -76,6 +76,11 @@ import akka.annotation.DoNotInherit */ def withMdc(newMdc: Map[String, String]): LoggingTestKit + /** + * After matching the expected number of hits, check for excess messages + */ + def withCheckExcess(checkExcess: Boolean): LoggingTestKit + /** * Matching events for which the supplied function returns`true`. */ diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/MailboxSelectorSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/MailboxSelectorSpec.scala index a4a1ef68a7..12994752e9 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/MailboxSelectorSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/MailboxSelectorSpec.scala @@ -74,7 +74,7 @@ class MailboxSelectorSpec extends ScalaTestWithActorTestKit(""" }, MailboxSelector.bounded(2)) actor ! "one" // actor will block here actor ! "two" - LoggingTestKit.deadLetters().expect { + LoggingTestKit.deadLetters().withCheckExcess(false).expect { // one or both of these doesn't fit in mailbox // depending on race with how fast actor consumes actor ! "three"