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 8f218556816f CAMEL-27108: camel-core - fix flaky
ForegroundTimeTaskTest.testRunNoMorePredicateMaxDuration (#30269)
8f218556816f is described below
commit 8f218556816f5114f82f698230bab28357d1c797
Author: Guillaume Nodet <[email protected]>
AuthorDate: Wed Nov 18 20:58:58 2026 +0100
CAMEL-27108: camel-core - fix flaky
ForegroundTimeTaskTest.testRunNoMorePredicateMaxDuration (#30269)
The test asserted exactly 5 iterations for a task with maxDuration=1000ms
and interval=200ms. On slow CI the time
budget can expire before the 5th iteration starts, and the test saw 3 or 4
iterations.
The test now checks what it is about: the time budget, not the iteration
cap of 50, stops the task. It asserts 1 to 5
iterations and an elapsed time of at least 1000ms.
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
.../apache/camel/support/task/task/ForegroundTimeTaskTest.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git
a/core/camel-core/src/test/java/org/apache/camel/support/task/task/ForegroundTimeTaskTest.java
b/core/camel-core/src/test/java/org/apache/camel/support/task/task/ForegroundTimeTaskTest.java
index cb704729e9cb..786e1ad179f4 100644
---
a/core/camel-core/src/test/java/org/apache/camel/support/task/task/ForegroundTimeTaskTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/support/task/task/ForegroundTimeTaskTest.java
@@ -103,7 +103,9 @@ class ForegroundTimeTaskTest extends TaskTestSupport {
@Test
@Timeout(20)
void testRunNoMorePredicateMaxDuration() {
- // It should run 5 times in 800 milliseconds because there is no
initial delay
+ // The time budget (1000ms) stops the task before hitting the
50-iteration cap.
+ // At 200ms per iteration, at most 5 iterations can fit in 1000ms;
count <= 5 and
+ // elapsed >= 1000ms are both deterministic (no CI timing dependency).
ForegroundTask task = Tasks.foregroundTask()
.withBudget(Budgets.iterationTimeBudget()
.withMaxDuration(Duration.ofMillis(1000))
@@ -114,7 +116,11 @@ class ForegroundTimeTaskTest extends TaskTestSupport {
.build();
task.run(camelContext, this::taskPredicate, new Object());
- assertEquals(maxIterations, taskCount.intValue());
+ int count = taskCount.intValue();
+ // the time budget stops the task: at most one iteration per interval
fits in maxDuration (1000 / 200 = 5),
+ // fewer when the machine is slow, and never the iteration cap of 50
+ assertTrue(count >= 1 && count <= 5, "Expected 1 to 5 iterations, but
ran " + count);
+ assertTrue(task.elapsed().toMillis() >= 1000, "The time budget should
be used up, elapsed: " + task.elapsed());
}
@DisplayName("Test that the task stops running once the predicate is true")