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 deef5a563680 Fix flaky Quartz tests: widen timing windows and fix 
latch timeout
deef5a563680 is described below

commit deef5a563680be80ab4e680bf8dabe979f5a054a
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sat Jul 18 11:46:49 2026 +0200

    Fix flaky Quartz tests: widen timing windows and fix latch timeout
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
 .../component/quartz/QuartzAddDynamicRouteTest.java      |  9 +++++++--
 .../QuartzAddRoutesAfterCamelContextStartedTest.java     | 11 ++++++++---
 .../quartz/QuartzCronRouteWithStartDateEndDateTest.java  | 16 +++++++++-------
 .../routepolicy/quartz/CronScheduledRoutePolicyTest.java |  6 ++++--
 4 files changed, 28 insertions(+), 14 deletions(-)

diff --git 
a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzAddDynamicRouteTest.java
 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzAddDynamicRouteTest.java
index 881f92acdbdf..4fa6c08e9849 100644
--- 
a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzAddDynamicRouteTest.java
+++ 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzAddDynamicRouteTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.quartz;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
@@ -39,12 +41,15 @@ public class QuartzAddDynamicRouteTest extends 
BaseQuartzTest {
         context.addRoutes(new RouteBuilder() {
             @Override
             public void configure() {
-                
from("quartz://myGroup/myTimerName?trigger.repeatInterval=2&trigger.repeatCount=1").routeId("myRoute")
+                // use a reasonable interval (200ms) so that the Quartz
+                // scheduler can reliably fire both triggers on loaded CI
+                // machines (2ms was far too tight for reliable scheduling)
+                
from("quartz://myGroup/myTimerName?trigger.repeatInterval=200&trigger.repeatCount=1").routeId("myRoute")
                         .to("direct:foo");
             }
         });
 
-        resultEndpoint.assertIsSatisfied();
+        MockEndpoint.assertIsSatisfied(context, 30, TimeUnit.SECONDS);
     }
 
     @Override
diff --git 
a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzAddRoutesAfterCamelContextStartedTest.java
 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzAddRoutesAfterCamelContextStartedTest.java
index 754c42f31be9..12c3fc4e3b0c 100644
--- 
a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzAddRoutesAfterCamelContextStartedTest.java
+++ 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzAddRoutesAfterCamelContextStartedTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.quartz;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
@@ -36,12 +38,15 @@ public class QuartzAddRoutesAfterCamelContextStartedTest 
extends BaseQuartzTest
         context.addRoutes(new RouteBuilder() {
             @Override
             public void configure() {
-                
from("quartz://myGroup/myTimerName?trigger.repeatInterval=100&trigger.repeatCount=1").to("mock:result");
+                // use a generous interval (500ms) so that the Quartz scheduler
+                // can reliably fire both the initial and repeat triggers even
+                // on heavily-loaded CI machines (100ms was too tight)
+                
from("quartz://myGroup/myTimerName?trigger.repeatInterval=500&trigger.repeatCount=1").to("mock:result");
             }
         });
 
-        // it should also work
-        MockEndpoint.assertIsSatisfied(context);
+        // it should also work — use timed assertion for CI resilience
+        MockEndpoint.assertIsSatisfied(context, 30, TimeUnit.SECONDS);
     }
 
 }
diff --git 
a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzCronRouteWithStartDateEndDateTest.java
 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzCronRouteWithStartDateEndDateTest.java
index aee0522abb03..d9d155745951 100644
--- 
a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzCronRouteWithStartDateEndDateTest.java
+++ 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzCronRouteWithStartDateEndDateTest.java
@@ -38,10 +38,11 @@ public class QuartzCronRouteWithStartDateEndDateTest 
extends BaseQuartzTest {
     public void testQuartzCronRouteWithStartDateEndDateTest() throws Exception 
{
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMinimumMessageCount(2);
-        mock.await(5, TimeUnit.SECONDS);
 
-        MockEndpoint.assertIsSatisfied(context);
-        assertThat(mock.getReceivedExchanges().size() <= 3, 
CoreMatchers.is(true));
+        // use timed assertion — the trigger starts 5s in the future and
+        // fires for 4 seconds, so messages arrive between ~5s and ~9s
+        MockEndpoint.assertIsSatisfied(context, 30, TimeUnit.SECONDS);
+        assertThat(mock.getReceivedExchanges().size() <= 5, 
CoreMatchers.is(true));
     }
 
     @Override
@@ -51,13 +52,14 @@ public class QuartzCronRouteWithStartDateEndDateTest 
extends BaseQuartzTest {
                 SimpleDateFormat dateFormat = new 
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
                 Calendar calendar = Calendar.getInstance();
                 calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
-                calendar.add(Calendar.SECOND, 3);
+                calendar.add(Calendar.SECOND, 5);
                 Date startDate = calendar.getTime();
-                calendar.add(Calendar.SECOND, 2);
+                calendar.add(Calendar.SECOND, 4);
                 Date endDate = calendar.getTime();
 
-                // triggers every 1th second at precise 00,01,02,03..59 with 
startAt and endAt exactly 2 second apart.
-                // configuration will create a maximum of three messages
+                // triggers every 1th second at precise 00,01,02,03..59 with 
startAt and endAt 4 seconds apart.
+                // give plenty of headroom (5s) for route setup before the 
trigger window opens,
+                // so that Quartz scheduler initialization doesn't eat into 
the firing window on loaded CI
                 fromF("quartz://myGroup/myTimerName?cron=0/1 * * * * 
?&trigger.startAt=%s&trigger.endAt=%s",
                         dateFormat.format(startDate), 
dateFormat.format(endDate)).to("mock:result");
             }
diff --git 
a/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicyTest.java
 
b/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicyTest.java
index c7086637ac8d..a75c639c0061 100644
--- 
a/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicyTest.java
+++ 
b/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicyTest.java
@@ -227,13 +227,15 @@ public class CronScheduledRoutePolicyTest {
             });
             context.start();
 
-            startedLatch.await(5000, TimeUnit.SECONDS);
+            // wait for the */3 cron to start the route (was 5000 SECONDS — a 
typo)
+            assertTrue(startedLatch.await(30, TimeUnit.SECONDS), "Route should 
have been started by cron");
 
             ServiceStatus startedStatus = 
context.getRouteController().getRouteStatus("test");
             assertTrue(startedStatus == ServiceStatus.Started || startedStatus 
== ServiceStatus.Starting);
             template.sendBody("direct:start", "Ready or not, Here, I come");
 
-            stoppedLatch.await(5000, TimeUnit.SECONDS);
+            // wait for the */6 cron to stop the route
+            assertTrue(stoppedLatch.await(30, TimeUnit.SECONDS), "Route should 
have been stopped by cron");
 
             ServiceStatus stoppedStatus = 
context.getRouteController().getRouteStatus("test");
             assertTrue(stoppedStatus == ServiceStatus.Stopped || stoppedStatus 
== ServiceStatus.Stopping);

Reply via email to