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


##########
AGENTS.md:
##########
@@ -163,10 +163,37 @@ await().atMost(20, TimeUnit.SECONDS)
        .untilAsserted(() -> assertEquals(1, context.getRoutes().size()));
 ```
 
+**MockEndpoint tests — prefer built-in timed assertions:**
+
+When the wait condition is "mock expectations are met", use `MockEndpoint`'s 
native timed
+assertion instead of wrapping with Awaitility. It is latch-based (more 
efficient than polling)
+and requires no external dependency:
+
+```java
+// Preferred — native, latch-based, returns as soon as expectations are met:
+MockEndpoint.assertIsSatisfied(context, 10, TimeUnit.SECONDS);

Review Comment:
   Good catch. Confirmed: `MockEndpoint.assertIsSatisfied(context)` (no timeout 
argument) **already waits 10 seconds** by default. The call chain is:
   
   1. `assertIsSatisfied(context)` → `mockEndpoint.assertIsSatisfied()` (line 
265)
   2. → `waitForCompleteLatch(resultWaitTime)` where `resultWaitTime` defaults 
to 0 (line 1985)
   3. → `long waitTime = timeout == 0 ? 10000L : timeout` (line 1997) — 
hardcoded 10s fallback
   
   So the timed overload `assertIsSatisfied(context, 10, TimeUnit.SECONDS)` is 
only needed when you want a **different** timeout. I've pushed a commit adding 
this note to the doc.
   
   Regarding existing Awaitility-wrapped MockEndpoint assertions — there are 
**58 instances** across the codebase:
   
   | Pattern | Count |
   |---|---|
   | `untilAsserted(() -> MockEndpoint.assertIsSatisfied(context))` | 20 |
   | `untilAsserted(() -> assertMockEndpointsSatisfied())` | 15 |
   | `untilAsserted(() -> mock.assertIsSatisfied())` | 11 |
   | `untilAsserted(resultEndpoint::assertIsSatisfied)` | 6 |
   | Other instance variants | 5 |
   | Double-wrapped with custom timeout | 1 |
   
   All of these are redundant — they poll (via Awaitility) a mechanism that 
already waits internally (via `CountDownLatch`). They could all be replaced 
with the plain `MockEndpoint.assertIsSatisfied(context)` call or the timed 
variant if a non-default timeout is needed.
   
   These are spread across `core/camel-core`, `camel-jms`, `camel-kafka`, 
`camel-quartz`, `camel-ftp`, `camel-aws2-s3`, `camel-aws2-kinesis`, 
`camel-mongodb`, `camel-mllp`, `camel-zeebe`, `camel-snmp`, `camel-netty`, 
`camel-sjms`, `camel-mybatis`, `camel-file-watch`, `camel-chatscript`, 
`camel-mina`, `camel-leveldb`, and others.



-- 
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