Skip to content

Commit df010e0

Browse files
committed
test: make mapWithResource cleanup tests deterministic
Motivation: The abrupt materializer termination tests used Source.single, which can complete across mapWithResource's async boundary and close the resource before shutdown. Modification: Keep the upstream open with Source.maybe and assert that the resource has not been closed before shutting down the materializer. Result: The tests now distinguish abrupt termination cleanup from normal upstream completion. Tests: - FlowMapWithResourceSpec on Scala 2.13 and Scala 3 - sbt +headerCheckAll - sbt checkCodeStyle - sbt validatePullRequest (3392 passed, 0 failed) References: Refs #3310
1 parent 15dcac1 commit df010e0

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/FlowMapWithResourceSpec.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ class FlowMapWithResourceSpec extends StreamSpec(UnboundedMailboxConfig) {
416416
val promise = Promise[Done]()
417417
val created = Promise[Done]()
418418
val matVal = Source
419-
.single(1)
419+
.maybe[Int]
420420
.mapWithResource(() => {
421421
created.trySuccess(Done)
422422
newBufferedReader()
@@ -429,6 +429,7 @@ class FlowMapWithResourceSpec extends StreamSpec(UnboundedMailboxConfig) {
429429
.mapConcat(identity)
430430
.runWith(Sink.never)(mat)
431431
Await.result(created.future, 3.seconds.dilated) shouldBe Done
432+
promise.isCompleted shouldBe false
432433
mat.shutdown()
433434
matVal.failed.futureValue shouldBe an[AbruptTerminationException]
434435
Await.result(promise.future, 3.seconds.dilated) shouldBe Done
@@ -531,10 +532,11 @@ class FlowMapWithResourceSpec extends StreamSpec(UnboundedMailboxConfig) {
531532
}
532533
}
533534
val matVal = Source
534-
.single(1)
535+
.maybe[Int]
535536
.mapWithResource(create, (_: AutoCloseable, count) => count)
536537
.runWith(Sink.never)(mat)
537538
Await.result(created.future, 3.seconds.dilated) shouldBe Done
539+
closedCounter.get shouldBe 0
538540
mat.shutdown()
539541
matVal.failed.futureValue shouldBe an[AbruptTerminationException]
540542
Await.result(promise.future, 3.seconds.dilated) shouldBe Done

0 commit comments

Comments
 (0)