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 7b827ba3679e CAMEL-23915: Fix flaky MockEndpointTimeClauseTest by
replacing Thread.sleep with Awaitility
7b827ba3679e is described below
commit 7b827ba3679e1b26281bb237bc9f5b76492068d3
Author: Guillaume Nodet <[email protected]>
AuthorDate: Mon Jul 6 11:11:07 2026 +0200
CAMEL-23915: Fix flaky MockEndpointTimeClauseTest by replacing Thread.sleep
with Awaitility
CAMEL-23915: Fix flaky MockEndpointTimeClauseTest by replacing Thread.sleep
with Awaitility
Replace all 10 Thread.sleep(50) calls with Awaitility-based assertions
that wait for mock endpoint received message counters. For tests with
between() timing bounds that require a minimum gap, use pollDelay to
ensure sufficient delay. Widen upper timing bounds to prevent flakiness
on slow CI systems.
Co-authored-by: Claude Opus 4.6 <[email protected]>
---
.../component/mock/MockEndpointTimeClauseTest.java | 36 +++++++++++-----------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git
a/core/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTimeClauseTest.java
b/core/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTimeClauseTest.java
index 9c508111d371..e2b07e60d3f2 100644
---
a/core/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTimeClauseTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTimeClauseTest.java
@@ -20,6 +20,7 @@ import java.util.Date;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
@@ -28,6 +29,7 @@ import org.apache.camel.StatefulService;
import org.apache.camel.builder.RouteBuilder;
import org.junit.jupiter.api.Test;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -81,11 +83,7 @@ public class MockEndpointTimeClauseTest extends
ContextTestSupport {
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(new Runnable() {
public void run() {
- try {
- Thread.sleep(50);
- } catch (Exception e) {
- // ignore
- }
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
mock.getReceivedCounter() >= 1);
if (isStarted(template)) {
template.sendBody("direct:a", "B");
}
@@ -141,7 +139,7 @@ public class MockEndpointTimeClauseTest extends
ContextTestSupport {
mock.message(0).arrives().noLaterThan(1).seconds().beforeNext();
template.sendBody("direct:a", "A");
- Thread.sleep(50);
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
mock.getReceivedCounter() >= 1);
template.sendBody("direct:a", "B");
assertMockEndpointsSatisfied();
@@ -154,7 +152,7 @@ public class MockEndpointTimeClauseTest extends
ContextTestSupport {
mock.message(1).arrives().noLaterThan(1).seconds().afterPrevious();
template.sendBody("direct:a", "A");
- Thread.sleep(50);
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
mock.getReceivedCounter() >= 1);
template.sendBody("direct:a", "B");
assertMockEndpointsSatisfied();
@@ -164,13 +162,13 @@ public class MockEndpointTimeClauseTest extends
ContextTestSupport {
public void testArrivesBeforeAndAfter() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(3);
- mock.message(1).arrives().noLaterThan(250).millis().afterPrevious();
- mock.message(1).arrives().noLaterThan(250).millis().beforeNext();
+ mock.message(1).arrives().noLaterThan(2).seconds().afterPrevious();
+ mock.message(1).arrives().noLaterThan(2).seconds().beforeNext();
template.sendBody("direct:a", "A");
- Thread.sleep(50);
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
mock.getReceivedCounter() >= 1);
template.sendBody("direct:a", "B");
- Thread.sleep(50);
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
mock.getReceivedCounter() >= 2);
template.sendBody("direct:a", "C");
assertMockEndpointsSatisfied();
@@ -180,10 +178,11 @@ public class MockEndpointTimeClauseTest extends
ContextTestSupport {
public void testArrivesWithinAfterPrevious() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(2);
- mock.message(1).arrives().between(10, 500).millis().afterPrevious();
+ mock.message(1).arrives().between(10, 2000).millis().afterPrevious();
template.sendBody("direct:a", "A");
- Thread.sleep(50);
+ await().pollDelay(20, TimeUnit.MILLISECONDS).atMost(5,
TimeUnit.SECONDS)
+ .until(() -> mock.getReceivedCounter() >= 1);
template.sendBody("direct:a", "B");
assertMockEndpointsSatisfied();
@@ -193,10 +192,11 @@ public class MockEndpointTimeClauseTest extends
ContextTestSupport {
public void testArrivesWithinBeforeNext() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(2);
- mock.message(0).arrives().between(10, 500).millis().beforeNext();
+ mock.message(0).arrives().between(10, 2000).millis().beforeNext();
template.sendBody("direct:a", "A");
- Thread.sleep(50);
+ await().pollDelay(20, TimeUnit.MILLISECONDS).atMost(5,
TimeUnit.SECONDS)
+ .until(() -> mock.getReceivedCounter() >= 1);
template.sendBody("direct:a", "B");
assertMockEndpointsSatisfied();
@@ -210,11 +210,11 @@ public class MockEndpointTimeClauseTest extends
ContextTestSupport {
template.sendBody("direct:a", "A");
template.sendBody("direct:a", "B");
- Thread.sleep(50);
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
mock.getReceivedCounter() >= 2);
template.sendBody("direct:a", "C");
- Thread.sleep(50);
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
mock.getReceivedCounter() >= 3);
template.sendBody("direct:a", "D");
- Thread.sleep(50);
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
mock.getReceivedCounter() >= 4);
template.sendBody("direct:a", "E");
assertMockEndpointsSatisfied();