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

Unpredictable behavior around during and atMost of Awaitility #180

Closed
uraniumdawn opened this issue Jul 12, 2020 · 9 comments
Closed

Unpredictable behavior around during and atMost of Awaitility #180

uraniumdawn opened this issue Jul 12, 2020 · 9 comments

Comments

@uraniumdawn
Copy link

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?

@grofoli
Copy link
Contributor

grofoli commented Jul 13, 2020

@johanhaleby I have seen this issue is under discussion also in Google Groups. I was wondering if I can help you with this - it is a long time since my last contribution :-) - but I would like to ask for a little guidance here if possible. So for example a branch with some failing tests that describe the expected behaviour and that I can make "green" with my contribution. Would this be a good approach/a help for you?

@johanhaleby
Copy link
Collaborator

@grofoli Thanks a lot for wanting to help :)

@uraniumdawn Could you perhaps provide a test case that shows the failing behavior?

@uraniumdawn
Copy link
Author

@johanhaleby Code snippet mentioned in ahead of this topic actually fails. And could be used as a test case suppose.

@grofoli
Copy link
Contributor

grofoli commented Jul 16, 2020

@johanhaleby @uraniumdawn I would really appreciate 2-3 unit tests that describe the expected behavior. Maybe I miss something here, does it really makes sense to use during and atMost with the same or almost the same values?

@uraniumdawn
Copy link
Author

uraniumdawn commented Jul 16, 2020

@grofoli As I said previously, I had to be sure that Kafka's topic doesn't receive new messages for a specific time. That is why I used during and atMost. To provide the exact time. No more, no less. I would appreciate getting another solution. As for the unit tests, I'll do ones.

@0xERR0R
Copy link

0xERR0R commented 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);
  }

@uraniumdawn
Copy link
Author

uraniumdawn commented Sep 8, 2020

@johanhaleby @grofoli @0xERR0R
You are right Oliver. It no makes sense to have a during and atMost at the same time. The first one covers my requirement. Sorry for wasting your time guys.

@johanhaleby
Copy link
Collaborator

@uraniumdawn Should we close this issue?

@uraniumdawn
Copy link
Author

@johanhaleby Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants