pjfanning commented on code in PR #1053:
URL: https://github.com/apache/incubator-pekko/pull/1053#discussion_r1468443645
##########
stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/FlowMapWithResourceSpec.scala:
##########
@@ -410,6 +410,24 @@ class FlowMapWithResourceSpec extends
StreamSpec(UnboundedMailboxConfig) {
Await.result(promise.future, 3.seconds) shouldBe Done
}
+ "will close the autocloseable resource" in {
+ val closedCounter = new AtomicInteger(0)
+ val create = () => new AutoCloseable {
+ override def close(): Unit = closedCounter.incrementAndGet()
+ }
+ val (pub, sub) = TestSource
+ .probe[Int]
+ .mapWithResource(create, (_, count) => count)
+ .toMat(TestSink.probe)(Keep.both)
+ .run()
+ sub.expectSubscription().request(2)
+ pub.sendNext(1)
+ sub.expectNext(1)
+ pub.sendComplete()
+ sub.expectComplete()
+ closedCounter.get shouldBe 1
Review Comment:
is there any chance that this test could check the function runs before the
close? I would create a class that is AutoCloseable - the close counts the
close calls, but the function that the class exposes is set up to check the
close count and if it is non-zero, the function should fail.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]