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 fc24d4429e7e CAMEL-26378: Attempt to stabilize
Test1SpringScheduledRoutePolicyTest (#30267)
fc24d4429e7e is described below
commit fc24d4429e7e2a236becff26b3265ab0e4c1f0b0
Author: Aurélien Pupier <[email protected]>
AuthorDate: Tue Nov 17 14:09:01 2026 +0100
CAMEL-26378: Attempt to stabilize Test1SpringScheduledRoutePolicyTest
(#30267)
This is an attempt to stabilize a flaky test. The root cause is deduced
from reading the code and the stack trace, it could not be reproduced.
Problem
-------
Test1SpringScheduledRoutePolicyTest.testScheduledStartRoutePolicy is
reported flaky in Develocity (about 76% of the builds on main, mean
execution time 16 seconds) and fails with:
ConditionTimeoutException: Assertion condition defined as a Lambda
expression in SpringScheduledRoutePolicyTest expected: <Started> but
was: <Stopped> within 5 seconds.
at SpringScheduledRoutePolicyTest.startTest(...java:59)
Investigation
-------------
SpringScheduledRoutePolicyTest.startTest() did:
1. start a CamelContext with the route "testRoute" using the policy
"startPolicy" (default autoStartup=true, so the route is Started)
2. context.getRouteController().stopRoute("testRoute", ...)
3. await up to 5s that the route status is Started again, expecting
the scheduled start of the policy to start it
"startPolicy" is defined in SimplePolicies.xml with routeStartDate = now
+ 1000ms (DateFactory.createDate(1000) is evaluated when the Spring
application context is created, before the CamelContext is started),
routeStartRepeatCount=1 and routeStartRepeatInterval=1000. So the Quartz
simple trigger fires twice: at +1s and at +2s from the creation of the
Spring context.
ScheduledRoutePolicy.onJobExecute(START) only acts when the route status
is Stopped (it then starts the route), or when the consumer is
suspended. When the route is Started it does nothing.
If the time between the creation of the Spring context and the manual
stopRoute (step 2) is more than ~2s, which can happen on a loaded CI
machine (JVM warmup, context startup, test parallelism), 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>".
The other tests of the class (stop, suspend, resume) do not have the
problem, as they just wait for the effect of the scheduled action on a
route started by the context.
Reproduction attempt
--------------------
Without the change, Test1SpringScheduledRoutePolicyTest was run in a loop
(mvn surefire:test pinned with taskset to 2 CPUs, while 6 busy loops were
competing for the same 2 CPUs). 26 runs were done, all successful, so the
flakiness was not reproduced locally and the root cause above is not
confirmed. The same loop was not run with the change.
Change
------
The route is now started with autoStartup=false in startTest(), and the
manual stopRoute is removed. The route starts as Stopped, so the only
way to get it Started is the scheduled start: the test checks what it is
meant to check, and it does not depend on how long the startup takes
anymore, as the start trigger can only fire while the route is Stopped.
The other tests keep the default autoStartup.
Co-authored-by: IBM Bob 2.2.1
---
.../routepolicy/quartz/SpringScheduledRoutePolicyTest.java | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git
a/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java
b/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java
index 40cb27d72aa1..919549193389 100644
---
a/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java
+++
b/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java
@@ -49,13 +49,13 @@ public abstract class SpringScheduledRoutePolicyTest {
public void startTest() throws Exception {
setUp();
- CamelContext context = startRouteWithPolicy("startPolicy");
+ // the route must not auto start: the scheduled start could otherwise
fire (twice) before the route is
+ // stopped by the test, when the startup is slow, and then nothing
would start the route again
+ CamelContext context = startRouteWithPolicy("startPolicy", false);
MockEndpoint mock = context.getEndpoint("mock:success",
MockEndpoint.class);
mock.expectedMinimumMessageCount(1);
- context.getRouteController().stopRoute("testRoute", 1000,
TimeUnit.MILLISECONDS);
-
Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(
() -> assertSame(ServiceStatus.Started,
context.getRouteController().getRouteStatus("testRoute")));
@@ -113,8 +113,12 @@ public abstract class SpringScheduledRoutePolicyTest {
mock.assertIsSatisfied();
}
- @SuppressWarnings("unchecked")
private CamelContext startRouteWithPolicy(String policyBeanName) throws
Exception {
+ return startRouteWithPolicy(policyBeanName, true);
+ }
+
+ @SuppressWarnings("unchecked")
+ private CamelContext startRouteWithPolicy(String policyBeanName, boolean
autoStartup) throws Exception {
CamelContext context = new DefaultCamelContext();
List<RouteDefinition> routes = (List<RouteDefinition>)
applicationContext.getBean("testRouteContext");
RoutePolicy policy = applicationContext.getBean(policyBeanName,
RoutePolicy.class);
@@ -122,6 +126,7 @@ public abstract class SpringScheduledRoutePolicyTest {
? policy instanceof SimpleScheduledRoutePolicy
: policy instanceof CronScheduledRoutePolicy);
routes.get(0).routePolicy(policy);
+ routes.get(0).autoStartup(autoStartup);
((ModelCamelContext) context).addRouteDefinitions(routes);
context.start();
return context;