question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unpredictable behavior around `during` and `atMost` of Awaitility

See original GitHub issue

While I was testing Kafka I end up with some issues around Awaitility. The goal was to test that Kafka topic doesn’t contain the new records for a specified time. This is the simplified scratch of my test but it shows the problem. I expect that ConditionTimeoutException doesn’t throw in this case. But it does.

public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        await("wait").during(5_000, TimeUnit.MILLISECONDS).atMost(5_000, TimeUnit.MILLISECONDS)
                .pollInterval(100, TimeUnit.MILLISECONDS)
                .until(() -> list, List::isEmpty);
}

I increased the atMost timeout to 5000 + pollInterval -> 5100 but still end up with an exception. On my local machine throwing exception was stoped closed the value of atMost timeout of 5170-5180. Should I keep something in mind? Or may the test isn’t correct?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
0xERR0Rcommented, Aug 26, 2020

If you use during together with atMost, the atMost time must be greater (await needs some time to evaluate the condition). This code works

  public static void main(String[] args) {
    List<String> list = new ArrayList<>();
    await("wait").during(5_000, TimeUnit.MILLISECONDS).atMost(5_500, TimeUnit.MILLISECONDS)
            .pollInterval(100, TimeUnit.MILLISECONDS)
            .until(() -> list, List::isEmpty);
  }
0reactions
uraniumdawncommented, Sep 13, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unpredictable behavior around `during` and `atMost` of ...
I increased the atMost timeout to 5000 + pollInterval -> 5100 but still end up with exception. On my local machine throwing exception...
Read more >
Unpredictable behavior around `during` and `atMost` - Google Groups
While I was testing Kafka I end up with some issues around Awaitility. The goal was to test that Kafka topic doesn't contain...
Read more >
Awaitility (Awaitility 4.1.1 API) - Javadoc.io
Awaitility is a small Java DSL for synchronizing (waiting for) asynchronous operations. ... Wait at most 5 seconds until customer status has been...
Read more >
JUnit 5 User Guide
This behavior can lead to undesirable side effects if the code that is executed within the executable or supplier relies on java.lang.
Read more >
"Thread.sleep" should not be used in tests - SonarSource Rules
Java static code analysis. Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your JAVA code.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found