Skip to content

Commit

Permalink
Fix and test for CompletableFuture.isDone behaviour
Browse files Browse the repository at this point in the history
Fixes #444
  • Loading branch information
FroMage committed Jun 7, 2024
1 parent 2f78403 commit 18d8a98
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public class CompletableFutureWrapper<T> extends CompletableFuture<T> implements

public CompletableFutureWrapper(SmallRyeThreadContext context, CompletableFuture<T> f, Executor executor, int flags) {
this.context = context;
this.f = f;
f.whenComplete((r, t) -> {
CompletableFuture<T> whenComplete = f.whenComplete((r, t) -> {
if (t != null) {
if (t instanceof CompletionException)
t = t.getCause();
Expand All @@ -40,6 +39,11 @@ public CompletableFutureWrapper(SmallRyeThreadContext context, CompletableFuture
});
this.executor = executor;
this.flags = flags;
if (!isDependent()) {
this.f = f;
} else {
this.f = whenComplete;
}
}

protected void checkDefaultExecutor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.smallrye.context.SmallRyeContextManager;
import io.smallrye.context.SmallRyeContextManagerProvider;
import io.smallrye.context.SmallRyeThreadContext;
import io.smallrye.context.test.util.AbstractTest;

class MiscTest extends AbstractTest {
Expand Down Expand Up @@ -71,4 +72,26 @@ void contextCaptureDependentStageForcedCompletion() throws ExecutionException, I
executorService.shutdown();
}

@Test
public void issue444() {
CompletableFuture<String> cs = new CompletableFuture<String>();

CompletableFuture<String> waitFor1 = cs.whenComplete((result, error) -> {
assertEquals(true, cs.isDone());
});

cs.complete("something");
waitFor1.join();

CompletableFuture<String> cs2 = new CompletableFuture<String>();
CompletableFuture<String> csw = SmallRyeThreadContext.getCurrentThreadContextOrDefaultContexts()
.withContextCapture(cs2);

CompletableFuture<String> waitFor2 = csw.whenComplete((result, error) -> {
assertEquals(true, csw.isDone());
});

cs2.complete("something");
waitFor2.join();
}
}

0 comments on commit 18d8a98

Please sign in to comment.