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 3fabcf060c8f CAMEL-23917: Fix flaky QuartzNameCollisionTest (#24441)
3fabcf060c8f is described below

commit 3fabcf060c8f9a5d86be111cd5f69185e2548dfe
Author: Guillaume Nodet <[email protected]>
AuthorDate: Mon Jul 6 10:06:44 2026 +0200

    CAMEL-23917: Fix flaky QuartzNameCollisionTest (#24441)
    
    CAMEL-23917: Fix flaky QuartzNameCollisionTest by replacing Thread.sleep 
with Awaitility
    
    Replace Thread.sleep(100) calls in testRestart() with Awaitility-based
    assertions that wait for the CamelContext to reach the expected state
    (started, suspended, stopped) after each lifecycle transition, making
    the test deterministic instead of relying on arbitrary sleep delays.
    
    Co-authored-by: Claude Opus 4.6 <[email protected]>
---
 .../component/quartz/QuartzNameCollisionTest.java      | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git 
a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzNameCollisionTest.java
 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzNameCollisionTest.java
index 627fdd385ab8..82c68031c45e 100644
--- 
a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzNameCollisionTest.java
+++ 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzNameCollisionTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.quartz;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.FailedToCreateRouteException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Test;
 import org.quartz.Scheduler;
@@ -123,15 +126,20 @@ public class QuartzNameCollisionTest {
 
         // traverse a litany of states
         assertDoesNotThrow(camel::start, "Start should have not thrown 
exception");
-        Thread.sleep(100);
+        Awaitility.await().atMost(5, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertTrue(camel.isStarted(), 
"CamelContext should be started"));
         assertDoesNotThrow(camel::suspend, "Suspend should not have thrown 
exception");
-        Thread.sleep(100);
+        Awaitility.await().atMost(5, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertTrue(camel.isSuspended(), 
"CamelContext should be suspended"));
         assertDoesNotThrow(camel::resume, "Resume should not have thrown 
exception");
-        Thread.sleep(100);
+        Awaitility.await().atMost(5, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertTrue(camel.isStarted(), 
"CamelContext should be started after resume"));
         assertDoesNotThrow(camel::stop, "Stop should not have thrown 
exception");
-        Thread.sleep(100);
+        Awaitility.await().atMost(5, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertTrue(camel.isStopped(), 
"CamelContext should be stopped"));
         assertDoesNotThrow(camel::start, "Start again should have thrown 
exception");
-        Thread.sleep(100);
+        Awaitility.await().atMost(5, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertTrue(camel.isStarted(), 
"CamelContext should be started again"));
         assertDoesNotThrow(camel::stop, "Final stop should have thrown 
exception");
     }
 

Reply via email to