This is an automated email from the ASF dual-hosted git repository.
apupier 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 3f05b58f3979 CAMEL-27280: Stabilize
SimpleScheduledRoutePolicyTest$SimpleTest1
3f05b58f3979 is described below
commit 3f05b58f39796c5ece88a36780027a56b70fab44
Author: Aurélien Pupier <[email protected]>
AuthorDate: Fri Nov 20 10:22:25 2026 +0100
CAMEL-27280: Stabilize SimpleScheduledRoutePolicyTest$SimpleTest1
SimpleScheduledRoutePolicyTest$SimpleTest1.testScheduledStartRoutePolicy is
reported flaky in Develocity (about 500 flaky runs in 2 months) and fails
with:
ConditionTimeoutException: Assertion condition defined as a Lambda
expression in SimpleScheduledRoutePolicyTest$SimpleTest1 expected:
<Started> but was: <Stopped> within 5 seconds.
Investigation
-------------
The test did:
1. start a CamelContext with the route "test" using a
SimpleScheduledRoutePolicy (default autoStartup=true, so the route is
Started), with routeStartDate = now + 500ms, routeStartRepeatCount=1
and
routeStartRepeatInterval=1000 (so the trigger fires at about +500ms and
+1500ms)
2. context.getRouteController().stopRoute("test")
3. await up to 5s that the route status is Started again, expecting the
scheduled start of the policy to start it
ScheduledRoutePolicy.onJobExecute(START) only acts when the route status is
Stopped (it then starts the route), or when the consumer is suspended or was
stopped by the scheduled suspend. When the route is Started it does nothing.
If the time between the creation of the route and the manual stopRoute (step
2) is longer than the trigger delays, which can happen on a loaded CI
machine,
both firings happen while the route is still Started and are no-ops. The
route
is then stopped by the test and nothing starts it again, so the test waits
5s
and fails with "expected: <Started> but was: <Stopped>".
This is the same cause as CAMEL-26378 for
Test1SpringScheduledRoutePolicyTest.
Reproduction
------------
Running the test 9 times with Maven pinned to 2 CPUs while 8 busy loops
competed for the same CPUs did not reproduce the failure (all runs passed),
as
for CAMEL-26378. Simulating the slow startup with a temporary
Thread.sleep(2000) between context.start() and stopRoute reproduced the
exact
failure of the Develocity report (2 out of 2 runs failed with "expected:
<Started> but was: <Stopped> within 5 seconds").
With the change, the same kind of stall no longer makes the test fail: with
a
temporary Thread.sleep(4000) after context.start() (longer than both trigger
delays) the test passes.
Change
------
- The route is declared with autoStartup(false) and the manual stopRoute is
removed. The route starts as Stopped, so the only way to get it Started is
the scheduled start; the start trigger can only fire while the route is
Stopped, whatever the duration of the startup.
- The test now asserts that the route is Stopped right after
context.start(),
to check that the Started status can only come from the scheduled start.
- The start date is moved from +500ms to +2000ms so the Stopped assertion
does
not race the first trigger. It stays well inside the 5s Awaitility
timeout.
Co-authored-by: IBM Bob 2.2.1
---
.../camel/routepolicy/quartz/SimpleScheduledRoutePolicyTest.java | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git
a/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleScheduledRoutePolicyTest.java
b/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleScheduledRoutePolicyTest.java
index 6d28d2af7c58..313a4f58c59b 100644
---
a/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleScheduledRoutePolicyTest.java
+++
b/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleScheduledRoutePolicyTest.java
@@ -50,19 +50,24 @@ public class SimpleScheduledRoutePolicyTest {
context.addRoutes(new RouteBuilder() {
public void configure() {
SimpleScheduledRoutePolicy policy = new
SimpleScheduledRoutePolicy();
- long startTime = System.currentTimeMillis() + 500;
+ // the route does not auto start (see below), so the
scheduled start is the only way to start it;
+ // the delay leaves time to check that the route is
stopped before the trigger fires
+ long startTime = System.currentTimeMillis() + 2000;
policy.setRouteStartDate(new Date(startTime));
policy.setRouteStartRepeatCount(1);
policy.setRouteStartRepeatInterval(1000);
from("direct:start")
.routeId("test")
+ .autoStartup(false)
.routePolicy(policy)
.to("mock:success");
}
});
context.start();
- context.getRouteController().stopRoute("test");
+
+ // the route is not started until the scheduled start fires
+ assertSame(ServiceStatus.Stopped,
context.getRouteController().getRouteStatus("test"));
Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() ->
{
assertSame(ServiceStatus.Started,
context.getRouteController().getRouteStatus("test"));