gnodet commented on code in PR #23180:
URL: https://github.com/apache/camel/pull/23180#discussion_r3233046523


##########
core/camel-core/src/test/java/org/apache/camel/impl/TwoRouteSuspendResumeTest.java:
##########
@@ -49,16 +49,10 @@ public void testSuspendResume() throws Exception {
 
         context.getRouteController().suspendRoute("foo");
 
-        // need to give seda consumer thread time to idle
-        await().atMost(1, TimeUnit.SECONDS).until(() -> {
-            return context.getEndpoint("seda:foo", 
SedaEndpoint.class).getQueue().isEmpty();
-        });
-
-        // even though we wait for the queues to empty, there is a race 
condition where the consumer
-        // may still process messages while it's being suspended due to 
asynchronous message handling.
-        // as a result, we need to wait a bit longer to ensure that the seda 
consumer is suspended before
-        // sending the next message.
-        Thread.sleep(1000L);

Review Comment:
   You're right, the `pollDelay` was before the condition check, but the 
original `Thread.sleep` was after the queue-empty await. Fixed in ef247030 — 
now split into two steps:
   
   1. `await().until(queue.isEmpty())` — checks the condition first
   2. `await().pollDelay(1s).untilAsserted(...)` — then gives the consumer 
thread time to idle
   
   This preserves the original semantics: wait for the queue to empty, *then* 
wait for the consumer to stop its poll loop.
   
   _Claude Code on behalf of Guillaume Nodet_



##########
core/camel-core/src/test/java/org/apache/camel/component/seda/SedaConsumerSuspendResumeTest.java:
##########
@@ -59,16 +59,12 @@ public void testSuspendResume() throws Exception {
         // mode where
         // it would poll and route (there is a little slack (up till 1 sec)
         // before suspension is empowered)
-        await().atMost(1, TimeUnit.SECONDS)
+        // wait for queues to empty and consumer to complete its poll cycle
+        await().pollDelay(1, TimeUnit.SECONDS)
+                .atMost(5, TimeUnit.SECONDS)
                 .until(() -> context.getEndpoint("seda:foo", 
SedaEndpoint.class).getQueue().isEmpty()
                         && context.getEndpoint("seda:bar", 
SedaEndpoint.class).getQueue().isEmpty());
 
-        // even though we wait for the queues to empty, there is a race 
condition where the consumer
-        // may still process messages while it's being suspended due to 
asynchronous message handling.
-        // as a result, we need to wait a bit longer to ensure that the seda 
consumer is suspended before
-        // sending the next message.
-        Thread.sleep(1000L);
-

Review Comment:
   Fixed in ef247030 — now split into two `await()` calls: first checks queues 
are empty, then uses `pollDelay(1s)` to give the consumer thread time to idle 
after the queues empty. The second await also asserts the consumer status is 
Suspended.
   
   _Claude Code on behalf of Guillaume Nodet_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to