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

davsclaus 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 1bda07698fc2 CAMEL-28110: camel-jetty - fix flaky 
JettyEventNotifierTest (#31359)
1bda07698fc2 is described below

commit 1bda07698fc2544d870c4ee16e18e676130cef2b
Author: AurĂ©lien Pupier <[email protected]>
AuthorDate: Fri Dec 4 14:45:15 2026 +0100

    CAMEL-28110: camel-jetty - fix flaky JettyEventNotifierTest (#31359)
    
    The test asserted on the notified events right after the HTTP response was
    received by the client. CamelServlet.afterProcess writes the response first
    and only then calls consumer.doneUoW(exchange), which fires the
    ExchangeCompleted/ExchangeFailed event. The client can therefore get the
    response and run its assertion before the last event is notified, giving
    "expected: <2> but was: <1>".
    
    Wait with Awaitility (atMost 10 seconds) for the expected list of events
    instead of asserting immediately, and use a CopyOnWriteArrayList as the
    events are added from a Jetty thread and read from the test thread.
    
    Co-authored-by: IBM Bob <[email protected]>
---
 .../camel/component/jetty/JettyEventNotifierTest.java   | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git 
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEventNotifierTest.java
 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEventNotifierTest.java
index eadf3ca58069..5277b1a9ad65 100644
--- 
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEventNotifierTest.java
+++ 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEventNotifierTest.java
@@ -16,8 +16,9 @@
  */
 package org.apache.camel.component.jetty;
 
-import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
@@ -27,11 +28,13 @@ import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
 import static io.restassured.RestAssured.given;
+import static org.awaitility.Awaitility.await;
 import static org.hamcrest.Matchers.is;
 
 public class JettyEventNotifierTest extends BaseJettyTest {
 
-    private final List<String> events = new ArrayList<>();
+    // events are notified from the Jetty thread, possibly after the HTTP 
response was received by the client
+    private final List<String> events = new CopyOnWriteArrayList<>();
 
     @Test
     void testEventNotifierOk() throws Exception {
@@ -57,9 +60,8 @@ public class JettyEventNotifierTest extends BaseJettyTest {
                     .statusCode(200)
                     .body(is("Bye World"));
 
-            Assertions.assertEquals(2, events.size());
-            Assertions.assertEquals("ExchangeCreated (failed:false)", 
events.get(0));
-            Assertions.assertEquals("ExchangeCompleted (failed:false)", 
events.get(1));
+            await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> 
Assertions.assertEquals(
+                    List.of("ExchangeCreated (failed:false)", 
"ExchangeCompleted (failed:false)"), events));
         } finally {
             context.stop();
         }
@@ -89,9 +91,8 @@ public class JettyEventNotifierTest extends BaseJettyTest {
                     .statusCode(500)
                     .body(is(""));
 
-            Assertions.assertEquals(2, events.size());
-            Assertions.assertEquals("ExchangeCreated (failed:false)", 
events.get(0));
-            Assertions.assertEquals("ExchangeFailed (failed:true)", 
events.get(1));
+            await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> 
Assertions.assertEquals(
+                    List.of("ExchangeCreated (failed:false)", "ExchangeFailed 
(failed:true)"), events));
         } finally {
             context.stop();
         }

Reply via email to