Skip to content

Commit

Permalink
Ensure that Quarkus.blockingExit is not called on main thread for tests
Browse files Browse the repository at this point in the history
StartupActionImpl#runMainClassBlocking which is used for
@QuarkusMainTest was incorrectly called on the main
thread before this change.

(cherry picked from commit 2131546)
  • Loading branch information
geoand authored and gsmet committed Nov 1, 2022
1 parent 990f6db commit 6637c77
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;

Expand Down Expand Up @@ -176,8 +177,23 @@ public void accept(Integer integer) {
Class<?> appClass = Class.forName(className, true, runtimeClassLoader);
Method start = appClass.getMethod("main", String[].class);
start.invoke(null, (Object) (args == null ? new String[0] : args));
Class<?> q = Class.forName(Quarkus.class.getName(), true, runtimeClassLoader);
q.getMethod("blockingExit").invoke(null);

CountDownLatch latch = new CountDownLatch(1);
new Thread(new Runnable() {
@Override
public void run() {
try {
Class<?> q = Class.forName(Quarkus.class.getName(), true, runtimeClassLoader);
q.getMethod("blockingExit").invoke(null);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
latch.countDown();
}
}
}).start();
latch.await();

Object newApplication = getCurrentApplication.invoke(null);
if (oldApplication == newApplication) {
//quarkus was not actually started by the main method
Expand Down

0 comments on commit 6637c77

Please sign in to comment.