From 6637c77b17db2c43f518de23e563af102a889a66 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 31 Oct 2022 14:56:46 +0200 Subject: [PATCH] Ensure that Quarkus.blockingExit is not called on main thread for tests StartupActionImpl#runMainClassBlocking which is used for @QuarkusMainTest was incorrectly called on the main thread before this change. (cherry picked from commit 2131546b1d42bb836e7f84b1c18e4879fa3256b1) --- .../runner/bootstrap/StartupActionImpl.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/StartupActionImpl.java b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/StartupActionImpl.java index 4e3873150da34..1f9380d33a961 100644 --- a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/StartupActionImpl.java +++ b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/StartupActionImpl.java @@ -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; @@ -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