This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new b419473442d2 CAMEL-23906: Fix flaky DelayerWhileShutdownTest on JDK 25 
(#24422)
b419473442d2 is described below

commit b419473442d2a366627e24d9bb3eb6d8d7e18283
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sun Jul 5 23:02:12 2026 +0200

    CAMEL-23906: Fix flaky DelayerWhileShutdownTest on JDK 25 (#24422)
    
    * CAMEL-23906: Fix flaky DelayerWhileShutdownTest on JDK 25
    
    Replace Phaser-based synchronization with a simpler CountDownLatch
    and use Awaitility for the mock endpoint assertion. The Phaser approach
    was timing-sensitive under JDK 25's thread scheduling. The new approach
    uses a latch to signal when the short-delay route starts processing and
    increases the long delay to 5000ms to ensure the context shutdown
    always interrupts it before it completes.
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    
    * CAMEL-23906: Address Copilot review feedback
    
    - Assert that the CountDownLatch returns true, failing fast with a
      diagnostic message if the short-delay route never starts processing
    - Increase the long delay from 5000ms to 30000ms so it is well above
      the 5-second Awaitility assertion timeout, eliminating the race
      where both could expire near the same instant under heavy CI load
    - Fix comment and rename variable for clarity
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    
    ---------
    
    Co-authored-by: Claude Opus 4.6 <[email protected]>
---
 .../camel/processor/DelayerWhileShutdownTest.java  | 30 ++++++++++++----------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/DelayerWhileShutdownTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/DelayerWhileShutdownTest.java
index 2c52c83febf2..fb42ab2cd86d 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/DelayerWhileShutdownTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/DelayerWhileShutdownTest.java
@@ -16,44 +16,48 @@
  */
 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;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 /**
  * 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 shortRouteStarted = 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 started processing its message
+        assertTrue(shortRouteStarted.await(5, TimeUnit.SECONDS),
+                "Short-delay route should have started processing within 5 
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");
+                // Long delay must be well above the assertion timeout (5s) to 
ensure
+                // the context shutdown always interrupts it before it 
completes
+                from("seda:a").delay(30000).to("mock:result");
+                from("seda:b").process(e -> 
shortRouteStarted.countDown()).delay(1).to("mock:result");
             }
         };
     }

Reply via email to