Skip to content

Commit

Permalink
Replace single thread executor with a Thread for simplification
Browse files Browse the repository at this point in the history
(cherry picked from commit 4d052eb)
  • Loading branch information
wndrws committed Nov 25, 2018
1 parent 1160ac2 commit 92f6812
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/test/java/ru/mail/polis/StartStopTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,18 @@ private void makeLifecycle() throws Exception {
private static void assertNotFinishesIn(final Duration timeout, final Executable executable)
throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final ExecutorService executor = Executors.newSingleThreadExecutor();
try {
executor.submit(() -> {
try {
executable.execute();
latch.countDown();
} catch (Throwable throwable) {
throwable.printStackTrace();
ExceptionUtils.throwAsUncheckedException(throwable);
}
});
boolean completedBeforeTimeout = latch.await(timeout.toMillis(), TimeUnit.MILLISECONDS);
if (completedBeforeTimeout) {
fail("Executable has completed before timeout while should not have been");
new Thread(() -> {
try {
executable.execute();
latch.countDown();
} catch (Throwable throwable) {
throwable.printStackTrace();
ExceptionUtils.throwAsUncheckedException(throwable);
}
} finally {
executor.shutdownNow();
}).start();
boolean completedBeforeTimeout = latch.await(timeout.toMillis(), TimeUnit.MILLISECONDS);
if (completedBeforeTimeout) {
fail("Executable has completed before timeout while should not have been");
}
}
}

0 comments on commit 92f6812

Please sign in to comment.