Skip to content

Commit 83af397

Browse files
oscerdclaude
andauthored
CAMEL-22325: Add AGENTS.md section to enforce Awaitility over Thread.sleep (#22371)
Signed-off-by: Andrea Cosentino <ancosen@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f8a490a commit 83af397

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,29 @@ When creating a PR, **always identify and request reviews** from the most releva
7676
- All code must pass formatting checks (`mvn formatter:format impsort:sort`) before pushing.
7777
- All generated files must be regenerated and committed (CI checks for uncommitted changes).
7878

79+
### Asynchronous Testing: Use Awaitility Instead of Thread.sleep
80+
81+
Do **NOT** use `Thread.sleep()` in test code. It leads to flaky, slow, and non-deterministic tests.
82+
Use the [Awaitility](https://github.com/awaitility/awaitility) library instead, which is already
83+
available as a test dependency in the project.
84+
85+
**Example — waiting for a route to be registered:**
86+
87+
```java
88+
import static org.awaitility.Awaitility.await;
89+
90+
await().atMost(20, TimeUnit.SECONDS)
91+
.untilAsserted(() -> assertEquals(1, context.getRoutes().size()));
92+
```
93+
94+
**Rules:**
95+
96+
- New test code MUST NOT introduce `Thread.sleep()` calls.
97+
- When modifying existing test code that contains `Thread.sleep()`, migrate it to Awaitility.
98+
- Always set an explicit `atMost` timeout to avoid hanging builds.
99+
- Use `untilAsserted` or `until` with a clear predicate — do not replace a sleep with a
100+
busy-wait loop.
101+
79102
### Issue Investigation (Before Implementation)
80103

81104
Before implementing a fix for a JIRA issue, **thoroughly investigate** the issue's validity and context.

0 commit comments

Comments
 (0)