Skip to content

Commit 68e6c1f

Browse files
committed
Fix flaky tests
1 parent 40f7e6a commit 68e6c1f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/test/java/dev/failsafe/functional/TimeoutTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public void testFallbackTimeoutWithBlockedSupplier() {
206206
fbStats.reset();
207207
}, Failsafe.with(fallback).compose(timeout), ctx -> {
208208
System.out.println("Executing");
209-
Thread.sleep(100);
209+
Thread.sleep(200);
210210
throw new Exception();
211211
}, (f, e) -> {
212212
assertEquals(e.getAttemptCount(), 1);
@@ -216,11 +216,11 @@ public void testFallbackTimeoutWithBlockedSupplier() {
216216
}, IllegalStateException.class);
217217

218218
// Test without interrupt
219-
Timeout<Object> timeout = withStatsAndLogs(Timeout.builder(Duration.ofMillis(1)), timeoutStats).build();
219+
Timeout<Object> timeout = withStatsAndLogs(Timeout.builder(Duration.ofMillis(100)), timeoutStats).build();
220220
test.accept(timeout);
221221

222222
// Test with interrupt
223-
timeout = withStatsAndLogs(Timeout.builder(Duration.ofMillis(1)).withInterrupt(), timeoutStats).build();
223+
timeout = withStatsAndLogs(Timeout.builder(Duration.ofMillis(100)).withInterrupt(), timeoutStats).build();
224224
test.accept(timeout);
225225
}
226226

src/test/java/dev/failsafe/issues/Issue231Test.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@
88

99
import java.time.Duration;
1010
import java.util.concurrent.ExecutionException;
11+
import java.util.concurrent.ExecutorService;
12+
import java.util.concurrent.Executors;
1113
import java.util.concurrent.atomic.AtomicBoolean;
1214

1315
import static org.testng.Assert.assertTrue;
1416

1517
@Test
1618
public class Issue231Test {
1719
/**
18-
* Timeout, even with interruption, should wait for the execution to complete.
20+
* Timeout, even with interruption, should wait for the execution to complete before completing the future.
1921
*/
2022
public void shouldWaitForExecutionCompletion() {
23+
// Use a separate executorService for this test in case the common pool is full
24+
ExecutorService executorService = Executors.newFixedThreadPool(2);
2125
Timeout<Object> timeout = Timeout.builder(Duration.ofMillis(100)).withInterrupt().build();
2226
AtomicBoolean executionCompleted = new AtomicBoolean();
23-
Asserts.assertThrows(() -> Failsafe.with(timeout).runAsync(() -> {
27+
Asserts.assertThrows(() -> Failsafe.with(timeout).with(executorService).runAsync(() -> {
2428
try {
2529
Thread.sleep(1000);
2630
} catch (InterruptedException ignore) {

0 commit comments

Comments
 (0)