You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "He-Pin (via GitHub)" <gi...@apache.org> on 2023/12/25 03:35:47 UTC

[PR] chore: Add tests for not invoking `onComplete` twice for statefulMap. [incubator-pekko]

He-Pin opened a new pull request, #876:
URL: https://github.com/apache/incubator-pekko/pull/876

   Motivation:
   Add more tests for not invoking `onComplete` twice for statefulMap, and later I will try to add `mapWithResource` operator.
   
   Result:
   Safer to coverage more cases.


-- 
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: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] chore: Add tests for not invoking `onComplete` twice for statefulMap. [incubator-pekko]

Posted by "laglangyue (via GitHub)" <gi...@apache.org>.
laglangyue commented on code in PR #876:
URL: https://github.com/apache/incubator-pekko/pull/876#discussion_r1436039230


##########
stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/FlowStatefulMapSpec.scala:
##########
@@ -371,5 +374,65 @@ class FlowStatefulMapSpec extends StreamSpec {
         .expectComplete()
       gate.ensure()
     }
+
+    "will not call `onComplete` twice if `f` fail" in {
+      val closedCounter = new AtomicInteger(0)
+      val probe = Source
+        .repeat(1)
+        .statefulMap(() => "opening resource")(
+          (_, _) => throw TE("failing read"),
+          _ => {
+            closedCounter.incrementAndGet()
+            None
+          })
+        .runWith(TestSink.probe[String])
+
+      probe.request(1)
+      probe.expectError(TE("failing read"))
+      closedCounter.get() should ===(1)
+    }
+
+    "will not call `onComplete` twice if both `f` and `onComplete` fail" in {
+      val closedCounter = new AtomicInteger(0)
+      val probe = Source
+        .repeat(1)
+        .statefulMap(() => "opening resource")((_, _) => throw TE("failing read"),
+          _ => {
+            closedCounter.incrementAndGet()
+            if (closedCounter.get == 1) {

Review Comment:
   line 401 and line 402 could be merged
   ```java
   if (closedCounter.incrementAndGet() == 1)
   ```



-- 
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: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] chore: Add tests for not invoking `onComplete` twice for statefulMap. [incubator-pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin merged PR #876:
URL: https://github.com/apache/incubator-pekko/pull/876


-- 
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: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org