Closed
Description
What do you think about making the dontCatchUncaughtExceptions
a setting by default?
I think, sometimes catchs of uncaught exceptions lead to unexpected behaviour in tests,
for example:
@Test
public void testFailed() throws InterruptedException {
ThreadPoolTaskExecutor taskExecutor = setUpExecutor();
taskExecutor.execute(new ErrorTestTask());
ListenableFuture<?> future = taskExecutor.submitListenable(new ErrorTestTask());
Awaitility.await()
.atMost(1, TimeUnit.SECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS)
.until(future::isDone);
}
@Test
public void testSuccess() throws InterruptedException {
ThreadPoolTaskExecutor taskExecutor = setUpExecutor();
taskExecutor.execute(new ErrorTestTask());
ListenableFuture<?> future = taskExecutor.submitListenable(new ErrorTestTask());
Thread.sleep(1000);
Assertions.assertThat(future.isDone()).isTrue();
}
private ThreadPoolTaskExecutor setUpExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setThreadNamePrefix(THREAD_NAME_PREFIX);
executor.setMaxPoolSize(1);
executor.afterPropertiesSet();
return executor;
}
private static class ErrorTestTask implements Runnable {
@Override
public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
throw new RuntimeException(Thread.currentThread().getName() + " -> Error");
}
}
When I replaced Thread.sleep on the Awaitility, I got a failed test.
I encountered this problem when I refactored a lot of tests to use the Awaitility instead of the Thread.sleep. It took quite a long time to understand that the problem was in another thread.
Metadata
Metadata
Assignees
Labels
No labels