Skip to content

Commit

Permalink
Activate request context on tests annotated with @RunOnVertContext
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Jun 11, 2021
1 parent bbccb99 commit f6f8c15
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;

import io.quarkus.arc.Arc;
import io.quarkus.arc.ManagedContext;
import io.quarkus.test.junit.TestMethodInvoker;
import io.quarkus.vertx.core.runtime.VertxCoreRecorder;
import io.vertx.core.Handler;
Expand Down Expand Up @@ -91,7 +93,17 @@ public RunTestMethodOnContextHandler(Object testInstance, Method targetMethod, L

@Override
public void handle(Void event) {
doRun();
ManagedContext requestContext = Arc.container().requestContext();
if (requestContext.isActive()) {
doRun();
} else {
try {
requestContext.activate();
doRun();
} finally {
requestContext.terminate();
}
}
}

private void doRun() {
Expand All @@ -108,7 +120,7 @@ public void accept(Object o) {
future.complete(testMethodResult);
}
} catch (Throwable t) {
future.completeExceptionally(t);
future.completeExceptionally(t.getCause());
}
}
}
Expand Down

0 comments on commit f6f8c15

Please sign in to comment.