Unrelated thread can cause Awaitility to throw an exception
See original GitHub issueAwaitility sets its own UncaughtExceptionHandler globally (ConditionAwaiter:49), i.e. all spawning threads are affected. This is pretty risky and can lead to many problems, one of them being:
During an awaitility until() call, if a new thread spawns and throws an exception, the exception handler for the awaitility call catches that exception and stores it assuming the exception was caused by the awaitility callable -> the awaitility call fails (eventually even before executing the callable).
Reproducer:
@Test
public void test() {
new Thread(() -> {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
new Thread(() -> {
throw new RuntimeException("Some irrelevant exception");
}).start();
}).start();
Awaitility.await()
.pollDelay(500, TimeUnit.MILLISECONDS)
.until(() -> true);
}
will fail with
java.lang.RuntimeException: Some irrelevant exception
at com.dynatrace.oneagent.atf.common.AwaitilityReproducer.lambda$null$0(AwaitilityReproducer.java:20)
at java.lang.Thread.run(Thread.java:748)
Tested with versions 1.7 and 3.1.2
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
Use Awaitility to determine something did not happen
Awaitility throws ConditionTimeoutException when timeout is reached. One way to check that nothing changed in a predetermined time is to ...
Read more >71744 – Concurrently throwing exceptions is not scalable
Multiple threads on multiple cores should be able to concurrently throw exceptions without bothering one another.
Read more >Using Awaitility with Cucumber for Eventual Consistency checks
Write stable end-to-end Cucumber tests with Awaitility to deal with asynchronous ... boolean correct) throws Exception { var stats = this.
Read more >Awaitility (Awaitility 4.1.1 API) - Javadoc.io
Awaitility is a small Java DSL for synchronizing (waiting for) asynchronous operations. ... Your test will not fail if another thread throws an...
Read more >Modern Best Practices for Testing in Java - Philipp Hauer's Blog
Avoid randomized data as it can lead to toggling tests which can be ... Don't @Test public void categoryQueryParameter() throws Exception ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dotstone May be something to reconsider now that two people have experienced issues with this in a short period of time. Thanks the feedback.
Ugh, I spent a whole day and a half tracking this down! It made it all the more tricky as things were failing from a cucumber test which does some magic with the stack trace so I would get a stack trace of a wholly unrelated exception into my cucumber steps. Anyways:
I second doing something with this. The wiki docs mentioning it are not enough, this needs a big fat warning! If I might suggest a solution: it looks like the uncaughtThroeabke is thrown in ConditionAwaiter. Is it possible to wrap it in an Awaitility exception type which: