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

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

commit c9c4fbe5c1a38ae86cf58881754dfbd5091c45c2
Author: Otavio Rodolfo Piske <angusyo...@gmail.com>
AuthorDate: Fri Sep 2 11:17:59 2022 +0200

    (chores) camel-jms: rework the high timeout test to reduce flakiness
---
 .../apache/camel/component/jms/JmsPollingConsumerTest.java | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git 
a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerTest.java
 
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerTest.java
index 7d1f8eb7ca2..bd0e9cc24d6 100644
--- 
a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerTest.java
+++ 
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerTest.java
@@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Nested;
@@ -133,14 +134,13 @@ public class JmsPollingConsumerTest extends 
AbstractJMSTest {
 
     @Nested
     class HighTimeOutTest {
-        private final CountDownLatch latch = new CountDownLatch(1);
+        private volatile String body;
 
         @BeforeEach
         void setupConsumer() {
             Executors.newSingleThreadExecutor().execute(() -> {
-                String body = 
consumer.receiveBody("activemq:queue.JmsPollingConsumerTest.start", 3000, 
String.class);
+                body = 
consumer.receiveBody("activemq:queue.JmsPollingConsumerTest.start", 3000, 
String.class);
                 template.sendBody("activemq:queue.JmsPollingConsumerTest.foo", 
body + " Claus");
-                latch.countDown();
             });
         }
 
@@ -149,12 +149,10 @@ public class JmsPollingConsumerTest extends 
AbstractJMSTest {
             MockEndpoint mock = getMockEndpoint("mock:result");
             mock.expectedBodiesReceived("Hello Claus");
 
-            assertFalse(latch.await(500, TimeUnit.MILLISECONDS),
-                    "No message should have been received within 500 
milliseconds because the test has not sent any");
-
+            assertNull(body, "No message should have been received because the 
test has not sent any");
             template.sendBody("direct:start", "Hello");
-            assertTrue(latch.await(5, TimeUnit.SECONDS),
-                    "A message should have been received but it was not");
+            Awaitility.await().atMost(5, TimeUnit.SECONDS)
+                    .until(() -> body != null);
 
             assertMockEndpointsSatisfied(30, TimeUnit.SECONDS);
         }

Reply via email to