Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature](test)Using Awaitility for Asynchronous Testing #37817

Closed
2 of 3 tasks
CalvinKirs opened this issue Jul 15, 2024 · 3 comments
Closed
2 of 3 tasks

[Feature](test)Using Awaitility for Asynchronous Testing #37817

CalvinKirs opened this issue Jul 15, 2024 · 3 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. kind/test

Comments

@CalvinKirs
Copy link
Member

CalvinKirs commented Jul 15, 2024

Search before asking

  • I had searched in the issues 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.
image
On one hand, Thread.sleep can lead to unstable test cases. On the other hand, it can also cause test cases to run longer than necessary.
https://github.com/awaitility/awaitility

Thread.sleep vs Awaitility

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.

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.

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

@CalvinKirs CalvinKirs added kind/feature Categorizes issue or PR as related to a new feature. kind/test labels Jul 15, 2024
@four1er
Copy link

four1er commented Jul 22, 2024

I want to try this issue, can you assign it to me?

@CalvinKirs
Copy link
Member Author

I want to try this issue, can you assign it to me?↳

Sure!
Feel free to contribute. Since this work involves a lot, you can break it down into small PRs and submit them. Of course, it’s best to comment below on which test cases you plan to refactor.

@Vallishp
Copy link
Contributor

Vallishp commented Aug 3, 2024

@CalvinKirs Hi , i have raise few MR for this task. pls help to review. thanks.

Vallishp added a commit to Vallishp/doris that referenced this issue Aug 4, 2024
dataroaring pushed a commit that referenced this issue Aug 5, 2024
…8814)

## Proposed changes

Issue Number: close #xxx
#37817
replace thread.sleep with awaitility util in some of compaction
testcases.
dataroaring pushed a commit that referenced this issue Aug 5, 2024
…8814)

## Proposed changes

Issue Number: close #xxx
#37817
replace thread.sleep with awaitility util in some of compaction
testcases.
dataroaring pushed a commit that referenced this issue Aug 6, 2024
## Proposed changes

Issue Number: close #xxx
#37817

use awaitility to replace thread.sleep in partial update regression
testcases
dataroaring pushed a commit that referenced this issue Aug 6, 2024
## Proposed changes

Issue Number: close #xxx
#37817

use awaitility to replace thread.sleep in partial update regression
testcases
yiguolei pushed a commit that referenced this issue Aug 6, 2024
…art (#38816)

## Proposed changes

Issue Number: close #xxx
#37817
replace thread.sleep with awaitility util in some of neredis_syntax test
cases.
yiguolei pushed a commit that referenced this issue Aug 6, 2024
…38831)

## Proposed changes

Issue Number: close #xxx
#37817
use awaitility in schema_change testcases.
airborne12 pushed a commit to airborne12/apache-doris that referenced this issue Aug 7, 2024
…art (apache#38816)

## Proposed changes

Issue Number: close #xxx
apache#37817
replace thread.sleep with awaitility util in some of neredis_syntax test
cases.
dataroaring pushed a commit that referenced this issue Aug 11, 2024
…art (#38816)

## Proposed changes

Issue Number: close #xxx
#37817
replace thread.sleep with awaitility util in some of neredis_syntax test
cases.
dataroaring pushed a commit that referenced this issue Aug 11, 2024
…38831)

## Proposed changes

Issue Number: close #xxx
#37817
use awaitility in schema_change testcases.
dataroaring pushed a commit that referenced this issue Aug 16, 2024
…art (#38816)

## Proposed changes

Issue Number: close #xxx
#37817
replace thread.sleep with awaitility util in some of neredis_syntax test
cases.
dataroaring pushed a commit that referenced this issue Aug 16, 2024
…38831)

## Proposed changes

Issue Number: close #xxx
#37817
use awaitility in schema_change testcases.
dataroaring pushed a commit that referenced this issue Aug 21, 2024
## Proposed changes

Issue Number: close #xxx
#37817
use awaitility.await() in schema testcases(part2)

Co-authored-by: Xinyi Zou <zouxinyi02@gmail.com>
yiguolei pushed a commit that referenced this issue Sep 18, 2024
## Proposed changes

Issue Number: close #xxx
#37817
use awaitility in few testcases
dataroaring pushed a commit that referenced this issue Oct 9, 2024
## Proposed changes

Issue Number: close #xxx
#37817
use awaitility.await() in schema testcases(part2)

Co-authored-by: Xinyi Zou <zouxinyi02@gmail.com>
dataroaring pushed a commit that referenced this issue Oct 9, 2024
#38836)

close #37817
use awaitility in  variant  schema_change testcases.
dataroaring pushed a commit that referenced this issue Oct 9, 2024
## Proposed changes

Issue Number: close #xxx
#37817
use awaitility in few testcases
hello-stephen pushed a commit that referenced this issue Oct 21, 2024
#37817
use awaitility in few testcases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. kind/test
Projects
None yet
Development

No branches or pull requests

3 participants