CalvinKirs opened a new issue, #37817: URL: https://github.com/apache/doris/issues/37817
### Search before asking - [X] I had searched in the [issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no similar issues. ### Description Currently our test codes include a lot of thread.sleep test codes, but this is not a recommended test method. <img width="750" alt="image" src="https://github.com/user-attachments/assets/a5438051-9d8b-4d17-a0fb-952fae6961ed"> ### Use case Using Awaitility instead of Thread.sleep for asynchronous testing in Java offers several advantages: #### Readability and Intent: **Awaitility**: Using Awaitility makes the test code more readable and expressive. It clearly communicates the intention to wait for a certain condition to be met. ```java Awaitility.await().until(() -> someConditionIsMet()); Thread.sleep: Using Thread.sleep adds an arbitrary delay without indicating why the delay is necessary, making the code less readable and harder to understand. ``` Thread.sleep(1000); #### Reliability: **Awaitility**: Waits until a specific condition is met, which makes the tests more reliable and less prone to intermittent failures. It ensures that the test only proceeds when the expected condition is true. **Thread.sleep**: Introduces a fixed delay, which can lead to flaky tests. If the condition is met sooner than the sleep time, the test unnecessarily waits. Conversely, if the condition is met after the sleep time, the test will fail. Timeout Management: Awaitility: Allows for configuring timeouts and poll intervals, giving fine-grained control over how long to wait and how frequently to check the condition. ```java Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> someConditionIsMet()); Thread.sleep: Error Messages: Awaitility: Provides clear error messages when a condition is not met within the specified timeout, making it easier to diagnose issues. Thread.sleep: If the condition is not met, the test may fail without a clear explanation, making debugging more challenging. Best Practices: Awaitility: Encourages best practices for writing asynchronous tests, such as waiting for conditions rather than introducing arbitrary delays. Thread.sleep: Using Thread.sleep is generally considered a bad practice in tests because it can lead to non-deterministic behavior and inefficiencies. In summary, Awaitility improves test readability, reliability, and maintainability by allowing precise control over waiting for asynchronous conditions, making it a better choice than using Thread.sleep. ### Related issues _No response_ ### Are you willing to submit PR? - [ ] Yes I am willing to submit a PR! ### Code of Conduct - [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- 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: commits-unsubscr...@doris.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org