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 9aaa8178c8b1 CAMEL-24037: Fix flaky camel-core tests using timed
assertions (#24635)
9aaa8178c8b1 is described below
commit 9aaa8178c8b127c5dfff3d6efddfe07ffe317143
Author: Guillaume Nodet <[email protected]>
AuthorDate: Mon Jul 13 09:03:01 2026 +0200
CAMEL-24037: Fix flaky camel-core tests using timed assertions (#24635)
CAMEL-24037: Fix flaky camel-core tests using timed assertions
- TwoSchedulerTest: use MockEndpoint.assertIsSatisfied with timeout, fix
assertSame to assertEquals for String comparison
- DistributedTimeoutTest: remove Awaitility wrapping MockEndpoint
assertions (anti-pattern), use direct timed assertions
- ThrottlingExceptionRoutePolicyOpenViaConfigTest: replace bare
assertMockEndpointsSatisfied with timed assertions
Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
.../org/apache/camel/component/scheduler/TwoSchedulerTest.java | 9 ++++++---
.../camel/processor/aggregator/DistributedTimeoutTest.java | 10 +++-------
.../ThrottlingExceptionRoutePolicyOpenViaConfigTest.java | 9 +++------
3 files changed, 12 insertions(+), 16 deletions(-)
diff --git
a/core/camel-core/src/test/java/org/apache/camel/component/scheduler/TwoSchedulerTest.java
b/core/camel-core/src/test/java/org/apache/camel/component/scheduler/TwoSchedulerTest.java
index 6c0af1466a32..61043277fb97 100644
---
a/core/camel-core/src/test/java/org/apache/camel/component/scheduler/TwoSchedulerTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/component/scheduler/TwoSchedulerTest.java
@@ -16,11 +16,14 @@
*/
package org.apache.camel.component.scheduler;
+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.Test;
-import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class TwoSchedulerTest extends ContextTestSupport {
@@ -29,12 +32,12 @@ public class TwoSchedulerTest extends ContextTestSupport {
getMockEndpoint("mock:a").expectedMinimumMessageCount(4);
getMockEndpoint("mock:b").expectedMinimumMessageCount(2);
- assertMockEndpointsSatisfied();
+ MockEndpoint.assertIsSatisfied(context, 30, TimeUnit.SECONDS);
// should use same thread as they share the same scheduler
String tn1 =
getMockEndpoint("mock:a").getReceivedExchanges().get(0).getMessage().getHeader("tn",
String.class);
String tn2 =
getMockEndpoint("mock:b").getReceivedExchanges().get(0).getMessage().getHeader("tn",
String.class);
- assertSame(tn1, tn2);
+ assertEquals(tn1, tn2);
}
@Override
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/DistributedTimeoutTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/DistributedTimeoutTest.java
index f884631e0b25..bde9485d48e6 100644
---
a/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/DistributedTimeoutTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/DistributedTimeoutTest.java
@@ -24,7 +24,6 @@ import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.processor.aggregate.MemoryAggregationRepository;
-import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
import static org.awaitility.Awaitility.await;
@@ -52,7 +51,7 @@ public class DistributedTimeoutTest extends
AbstractDistributedTest {
template2.sendBodyAndHeader("direct:start", "B", "id", 123);
// wait a bit until the timeout was triggered
- await().atMost(2, TimeUnit.SECONDS).until(() -> invoked.get() == 1);
+ await().atMost(5, TimeUnit.SECONDS).until(() -> invoked.get() == 1);
mock.assertIsSatisfied();
mock2.assertIsSatisfied();
@@ -73,11 +72,8 @@ public class DistributedTimeoutTest extends
AbstractDistributedTest {
template2.sendBodyAndHeader("direct:start", "B", "id", 123);
template2.sendBodyAndHeader("direct:start", "C", "id", 123);
- Awaitility.await().untilAsserted(() -> {
- // should complete before timeout
- mock2.assertIsSatisfied(500);
- mock.assertIsSatisfied(500);
- });
+ MockEndpoint.assertIsSatisfied(context, 30, TimeUnit.SECONDS);
+ MockEndpoint.assertIsSatisfied(context2, 30, TimeUnit.SECONDS);
// should have not invoked the timeout method anymore
assertEquals(1, invoked.get());
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/throttle/ThrottlingExceptionRoutePolicyOpenViaConfigTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/throttle/ThrottlingExceptionRoutePolicyOpenViaConfigTest.java
index 35769a3abade..58c020b9e0b1 100644
---
a/core/camel-core/src/test/java/org/apache/camel/processor/throttle/ThrottlingExceptionRoutePolicyOpenViaConfigTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/throttle/ThrottlingExceptionRoutePolicyOpenViaConfigTest.java
@@ -65,8 +65,7 @@ public class ThrottlingExceptionRoutePolicyOpenViaConfigTest
extends ContextTest
template.sendBody(url, "MessageRound1 " + i);
}
result.expectedMessageCount(size);
- result.setResultWaitTime(5000);
- assertMockEndpointsSatisfied();
+ MockEndpoint.assertIsSatisfied(context, 30, TimeUnit.SECONDS);
// set keepOpen to true
policy.setKeepOpen(true);
@@ -86,8 +85,7 @@ public class ThrottlingExceptionRoutePolicyOpenViaConfigTest
extends ContextTest
// should not close b/c keepOpen is true
result.expectedMessageCount(size + 1);
- result.setResultWaitTime(2000);
- assertMockEndpointsSatisfied();
+ MockEndpoint.assertIsSatisfied(context, 30, TimeUnit.SECONDS);
// set keepOpen to false
policy.setKeepOpen(false);
@@ -97,8 +95,7 @@ public class ThrottlingExceptionRoutePolicyOpenViaConfigTest
extends ContextTest
// it should close b/c keepOpen is false — queued messages should now
arrive
result.expectedMessageCount(size * 2 + 1);
- result.setResultWaitTime(5000);
- assertMockEndpointsSatisfied();
+ MockEndpoint.assertIsSatisfied(context, 30, TimeUnit.SECONDS);
}
@Override