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 0b7fecc95076 CAMEL-23884: Fix flaky NatsConsumerWithRedeliveryIT by 
using Awaitility
0b7fecc95076 is described below

commit 0b7fecc95076c879f833c2b5bde916721a057f79
Author: Guillaume Nodet <[email protected]>
AuthorDate: Thu Jul 2 23:57:20 2026 +0200

    CAMEL-23884: Fix flaky NatsConsumerWithRedeliveryIT by using Awaitility
    
    Fix the intermittently failing NatsConsumerWithRedeliveryIT.testConsumer
    by moving mock expectations before message sends (fixing a CountDownLatch
    race) and replacing fixed-timing assertIsSatisfied/assertPeriod calls
    with Awaitility's adaptive polling.
    
    Closes #24388
---
 .../integration/NatsConsumerWithRedeliveryIT.java     | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git 
a/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerWithRedeliveryIT.java
 
b/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerWithRedeliveryIT.java
index 45cdb7abb371..b3dbd92db2dc 100644
--- 
a/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerWithRedeliveryIT.java
+++ 
b/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerWithRedeliveryIT.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.nats.integration;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.EndpointInject;
 import org.apache.camel.LoggingLevel;
 import org.apache.camel.RuntimeCamelException;
@@ -23,6 +25,9 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 public class NatsConsumerWithRedeliveryIT extends NatsITSupport {
 
     private static final int REDELIVERY_COUNT = 2;
@@ -36,16 +41,18 @@ public class NatsConsumerWithRedeliveryIT extends 
NatsITSupport {
     @Test
     public void testConsumer() throws Exception {
         mockResultEndpoint.setExpectedMessageCount(1);
-        mockResultEndpoint.setAssertPeriod(1000);
+        exception.setExpectedMessageCount(1);
 
         template.sendBody("direct:send", "test");
         template.sendBody("direct:send", "golang");
 
-        exception.setExpectedMessageCount(1);
-
-        exception.assertIsSatisfied();
-
-        mockResultEndpoint.assertIsSatisfied();
+        await().atMost(30, TimeUnit.SECONDS)
+                .untilAsserted(() -> {
+                    assertEquals(1, exception.getReceivedCounter(),
+                            "mock:exception should have received the message 
after redelivery exhaustion");
+                    assertEquals(1, mockResultEndpoint.getReceivedCounter(),
+                            "mock:result should have received the non-failing 
message");
+                });
     }
 
     @Override

Reply via email to