This is an automated email from the ASF dual-hosted git repository.
acosentino 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 83af3977b040 CAMEL-22325: Add AGENTS.md section to enforce Awaitility
over Thread.sleep (#22371)
83af3977b040 is described below
commit 83af3977b0400a734f63606ba57a15b7386669f3
Author: Andrea Cosentino <[email protected]>
AuthorDate: Wed Apr 1 13:53:54 2026 +0200
CAMEL-22325: Add AGENTS.md section to enforce Awaitility over Thread.sleep
(#22371)
Signed-off-by: Andrea Cosentino <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
---
AGENTS.md | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/AGENTS.md b/AGENTS.md
index fa6962049470..ade9d018214b 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -76,6 +76,29 @@ When creating a PR, **always identify and request reviews**
from the most releva
- All code must pass formatting checks (`mvn formatter:format impsort:sort`)
before pushing.
- All generated files must be regenerated and committed (CI checks for
uncommitted changes).
+### Asynchronous Testing: Use Awaitility Instead of Thread.sleep
+
+Do **NOT** use `Thread.sleep()` in test code. It leads to flaky, slow, and
non-deterministic tests.
+Use the [Awaitility](https://github.com/awaitility/awaitility) library
instead, which is already
+available as a test dependency in the project.
+
+**Example — waiting for a route to be registered:**
+
+```java
+import static org.awaitility.Awaitility.await;
+
+await().atMost(20, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(1, context.getRoutes().size()));
+```
+
+**Rules:**
+
+- New test code MUST NOT introduce `Thread.sleep()` calls.
+- When modifying existing test code that contains `Thread.sleep()`, migrate it
to Awaitility.
+- Always set an explicit `atMost` timeout to avoid hanging builds.
+- Use `untilAsserted` or `until` with a clear predicate — do not replace a
sleep with a
+ busy-wait loop.
+
### Issue Investigation (Before Implementation)
Before implementing a fix for a JIRA issue, **thoroughly investigate** the
issue's validity and context.