Awaitility hiding exceptions on the same thread
See original GitHub issueThis is a small program that demonstrates the behavior I’m seeing that appears to be a bug.
Actual behavior:
When this runs it exits and prints IllegalArgumentException stack trace like a normal java program. The weird behavior is if you comment out the line .dontCatchUncaughtExceptions()
, it will exit with status code 1 and not print the exception.
Expected behavior: I would expect awaitility to not affect exceptions thrown in the same thread and outside its until() {} block.
Version: <groupId>org.awaitility</groupId> <artifactId>awaitility</artifactId> <version>3.1.2</version>
public static void main(final String... args) throws Exception {
final AtomicInteger count = new AtomicInteger(0);
await()
.dontCatchUncaughtExceptions()
.ignoreExceptionsMatching(instanceOf(IOException.class))
.atMost(3, TimeUnit.MINUTES)
.until(() -> {
count.incrementAndGet();
return count.get() > 3;
});
if (true) {
System.out.println("throwing an exception");
throw new IllegalArgumentException("broken");
}
System.out.println("Already exited so you won't see this");
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Asynchronous tests, the Awaitility and uncaught exceptions ...
One example of such test: @Test public void asyncMethodListener() throws Exception { // Arrange originalThreadName = Thread.currentThread().
Read more >Developers - Awatility-4.0.2 hiding exceptions on the same thread -
I was under an impression that 'dontCatchUncaughtExceptions' should throw the RuntimeException when occurred. However, it skips throwing the exception over ...
Read more >Awaitility (Awaitility 3.0.0 API) - Javadoc.io
Instruct Awaitility to catch uncaught exceptions from other threads by default. This is useful in multi-threaded systems when you want your test to...
Read more >Code Smell: "Thread.sleep" should not be used in tests
Using Thread.sleep in a test is just generally a bad idea. It creates brittle tests that can fail unpredictably depending on environment ("Passes...
Read more >Exception Handling in Java - Baeldung
Checked exceptions; Unchecked exceptions / Runtime exceptions; Errors. Runtime and unchecked exceptions refer to the same thing. We can often ...
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
I opened a PR few minutes ago. Please be aware that writing a unit test similar to the main method below is not easily possible, because the JUnit Framework has an own Exception handling. Therefore I decided to test an implementation detail in the unit test, namely the reset of the original defaultUncaughtExceptionHandler.
The following main method throws an IllegalArgumentException exception, which proves that the Awaitility does NOT hide exception on the main thread anymore.
Thanks for trying it out, reviewing and reminding me Oliver! 😃 I’ll try release 4.0.2 now. I can’t thank you enough for your efforts on this release!
On Thu, Jan 2, 2020 at 8:38 PM Oliver Grof notifications@github.com wrote: