diff --git a/src/test/java/dev/failsafe/functional/TimeoutTest.java b/src/test/java/dev/failsafe/functional/TimeoutTest.java index 334d6aa2..3fc5b06e 100644 --- a/src/test/java/dev/failsafe/functional/TimeoutTest.java +++ b/src/test/java/dev/failsafe/functional/TimeoutTest.java @@ -206,7 +206,7 @@ public void testFallbackTimeoutWithBlockedSupplier() { fbStats.reset(); }, Failsafe.with(fallback).compose(timeout), ctx -> { System.out.println("Executing"); - Thread.sleep(100); + Thread.sleep(200); throw new Exception(); }, (f, e) -> { assertEquals(e.getAttemptCount(), 1); @@ -216,11 +216,11 @@ public void testFallbackTimeoutWithBlockedSupplier() { }, IllegalStateException.class); // Test without interrupt - Timeout timeout = withStatsAndLogs(Timeout.builder(Duration.ofMillis(1)), timeoutStats).build(); + Timeout timeout = withStatsAndLogs(Timeout.builder(Duration.ofMillis(100)), timeoutStats).build(); test.accept(timeout); // Test with interrupt - timeout = withStatsAndLogs(Timeout.builder(Duration.ofMillis(1)).withInterrupt(), timeoutStats).build(); + timeout = withStatsAndLogs(Timeout.builder(Duration.ofMillis(100)).withInterrupt(), timeoutStats).build(); test.accept(timeout); } diff --git a/src/test/java/dev/failsafe/issues/Issue231Test.java b/src/test/java/dev/failsafe/issues/Issue231Test.java index 3478be93..dce893a5 100644 --- a/src/test/java/dev/failsafe/issues/Issue231Test.java +++ b/src/test/java/dev/failsafe/issues/Issue231Test.java @@ -8,6 +8,8 @@ import java.time.Duration; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicBoolean; import static org.testng.Assert.assertTrue; @@ -15,12 +17,14 @@ @Test public class Issue231Test { /** - * Timeout, even with interruption, should wait for the execution to complete. + * Timeout, even with interruption, should wait for the execution to complete before completing the future. */ public void shouldWaitForExecutionCompletion() { + // Use a separate executorService for this test in case the common pool is full + ExecutorService executorService = Executors.newFixedThreadPool(2); Timeout timeout = Timeout.builder(Duration.ofMillis(100)).withInterrupt().build(); AtomicBoolean executionCompleted = new AtomicBoolean(); - Asserts.assertThrows(() -> Failsafe.with(timeout).runAsync(() -> { + Asserts.assertThrows(() -> Failsafe.with(timeout).with(executorService).runAsync(() -> { try { Thread.sleep(1000); } catch (InterruptedException ignore) {