gnodet commented on code in PR #24422:
URL: https://github.com/apache/camel/pull/24422#discussion_r3525624669


##########
core/camel-core/src/test/java/org/apache/camel/processor/DelayerWhileShutdownTest.java:
##########
@@ -16,44 +16,45 @@
  */
 package org.apache.camel.processor;
 
-import java.util.concurrent.Phaser;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
+
 /**
  * Delayer while shutting down so its interrupted and will also stop.
  */
 public class DelayerWhileShutdownTest extends ContextTestSupport {
 
-    private final Phaser phaser = new Phaser(2);
-
-    @BeforeEach
-    void sendEarly() {
-        template.sendBody("seda:a", "Long delay");
-        template.sendBody("seda:b", "Short delay");
-    }
+    private final CountDownLatch shortDelayStarted = new CountDownLatch(1);
 
     @Test
     public void testSendingMessageGetsDelayed() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedBodiesReceived("Short delay");
 
-        phaser.awaitAdvanceInterruptibly(0, 5000, TimeUnit.SECONDS);
+        template.sendBody("seda:a", "Long delay");
+        template.sendBody("seda:b", "Short delay");
+
+        // Wait until the short-delay route has entered the delay phase,
+        // ensuring both routes are actively processing
+        shortDelayStarted.await(5, TimeUnit.SECONDS);

Review Comment:
   Fixed in ebe472b: the latch return value is now asserted with `assertTrue()` 
and a diagnostic message. Variable and comment also corrected.



##########
core/camel-core/src/test/java/org/apache/camel/processor/DelayerWhileShutdownTest.java:
##########
@@ -16,44 +16,45 @@
  */
 package org.apache.camel.processor;
 
-import java.util.concurrent.Phaser;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
+
 /**
  * Delayer while shutting down so its interrupted and will also stop.
  */
 public class DelayerWhileShutdownTest extends ContextTestSupport {
 
-    private final Phaser phaser = new Phaser(2);
-
-    @BeforeEach
-    void sendEarly() {
-        template.sendBody("seda:a", "Long delay");
-        template.sendBody("seda:b", "Short delay");
-    }
+    private final CountDownLatch shortDelayStarted = new CountDownLatch(1);
 
     @Test
     public void testSendingMessageGetsDelayed() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedBodiesReceived("Short delay");
 
-        phaser.awaitAdvanceInterruptibly(0, 5000, TimeUnit.SECONDS);
+        template.sendBody("seda:a", "Long delay");
+        template.sendBody("seda:b", "Short delay");
+
+        // Wait until the short-delay route has entered the delay phase,
+        // ensuring both routes are actively processing
+        shortDelayStarted.await(5, TimeUnit.SECONDS);
 
-        assertMockEndpointsSatisfied();
+        await().atMost(5, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertMockEndpointsSatisfied());
     }
 
     @Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                from("seda:a").process(e -> 
phaser.arriveAndAwaitAdvance()).delay(1000).to("mock:result");
-                from("seda:b").process(e -> 
phaser.arriveAndAwaitAdvance()).delay(1).to("mock:result");
+                from("seda:a").delay(5000).to("mock:result");

Review Comment:
   Fixed in ebe472b: the long delay is now 30000ms (30s), well above the 5s 
Awaitility assertion timeout, eliminating this race.



-- 
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]

Reply via email to