Skip to content

Commit 0a44a9a

Browse files
committed
Add onTimeout cancellation test
1 parent f8b2811 commit 0a44a9a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/test/java/net/tascalate/concurrent/DependentPromiseTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.junit.Assert.assertTrue;
2020

2121
import java.util.concurrent.CompletableFuture;
22+
import java.util.concurrent.TimeUnit;
2223
import java.util.concurrent.atomic.AtomicInteger;
2324

2425
import org.junit.After;
@@ -353,6 +354,19 @@ public void testHandleAsyncRecursiveCancellation2() {
353354
assertCancelled("s2", s2);
354355
}
355356

357+
@Test
358+
public void test_orTimeout_does_not_break_cancellation_ability() {
359+
State s1 = new State();
360+
Promise<Void> p = CompletableTask
361+
.runAsync(() -> longTask(5, s1), executor)
362+
.dependent()
363+
.orTimeout(2, TimeUnit.SECONDS, true, true);
364+
trySleep(2);
365+
p.cancel(true);
366+
trySleep(1);
367+
assertCancelled("s1", s1);
368+
}
369+
356370
private DependentPromise<Void> runDepedentAsync(Runnable r) {
357371
return CompletableTask.runAsync(r, executor).dependent();
358372
}

0 commit comments

Comments
 (0)