Also dilate the initial delay when testing timeouts in akka-stream-testkit

This commit is contained in:
Marcos Pereira 2021-08-23 11:55:49 -04:00
parent 8ad0b992d6
commit d22e4becd1
No known key found for this signature in database
GPG key ID: F7EBB0FF122A3D87

View file

@ -8,8 +8,9 @@ import scala.concurrent.duration._
import akka.stream.scaladsl.Source import akka.stream.scaladsl.Source
import akka.stream.testkit.scaladsl.TestSink import akka.stream.testkit.scaladsl.TestSink
import akka.testkit.AkkaSpec
import akka.testkit.EventFilter import akka.testkit._
import akka.testkit.TestEvent.Mute import akka.testkit.TestEvent.Mute
import akka.testkit.TestEvent.UnMute import akka.testkit.TestEvent.UnMute
@ -121,13 +122,17 @@ class StreamTestKitSpec extends AkkaSpec {
"#expectNextWithTimeoutPF should fail after timeout when element delayed" in { "#expectNextWithTimeoutPF should fail after timeout when element delayed" in {
intercept[AssertionError] { intercept[AssertionError] {
val timeout = 100.millis val timeout = 100.millis
val overTimeout = timeout + 50.millis // Initial delay is longer than the timeout so an exception will be thrown.
// It also needs to be dilated since the testkit will dilate the timeout
// accordingly to `-Dakka.test.timefactor` value.
val initialDelay = (timeout * 2).dilated
Source Source
.tick(overTimeout, 1.millis, 1) .tick(initialDelay, 1.millis, 1)
.runWith(TestSink.probe) .runWith(TestSink.probe)
.request(1) .request(1)
.expectNextWithTimeoutPF(timeout, { .expectNextWithTimeoutPF(timeout, {
case 1 => case 1 =>
system.log.info("Message received :(")
}) })
}.getMessage should include("timeout") }.getMessage should include("timeout")
@ -160,9 +165,12 @@ class StreamTestKitSpec extends AkkaSpec {
"#expectNextChainingPF should fail after timeout when element delayed" in { "#expectNextChainingPF should fail after timeout when element delayed" in {
intercept[AssertionError] { intercept[AssertionError] {
val timeout = 100.millis val timeout = 100.millis
val overTimeout = timeout + 50.millis // Initial delay is longer than the timeout so an exception will be thrown.
// It also needs to be dilated since the testkit will dilate the timeout
// accordingly to `-Dakka.test.timefactor` value.
val initialDelay = (timeout * 2).dilated
Source Source
.tick(overTimeout, 1.millis, 1) .tick(initialDelay, 1.millis, 1)
.runWith(TestSink.probe) .runWith(TestSink.probe)
.request(1) .request(1)
.expectNextChainingPF(timeout, { .expectNextChainingPF(timeout, {