From 203ecbcda647ae0306780cffd24ea4fe7c38e9f6 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 8 Jun 2021 09:51:33 +0300 Subject: [PATCH] Give processes launched by @QuarkusIntegrationTest a chance to terminate normally This is especially useful when launching a docker container because the '--rm' flag of 'docker run' takes only if the process is terminated normally Fixes: #17737 (cherry picked from commit de12100f956001be23da4caab206261004a483bf) --- .../io/quarkus/test/common/LauncherUtil.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test-framework/common/src/main/java/io/quarkus/test/common/LauncherUtil.java b/test-framework/common/src/main/java/io/quarkus/test/common/LauncherUtil.java index 7dd17e1412445..42ceb92438d8c 100644 --- a/test-framework/common/src/main/java/io/quarkus/test/common/LauncherUtil.java +++ b/test-framework/common/src/main/java/io/quarkus/test/common/LauncherUtil.java @@ -70,7 +70,7 @@ static ListeningAddress waitForCapturedListeningData(Process quarkusProcess, Pat if (result != null) { return result; } - quarkusProcess.destroyForcibly(); + destroyProcess(quarkusProcess); throw new IllegalStateException( "Unable to determine the status of the running process. See the above logs for details"); } catch (InterruptedException e) { @@ -78,6 +78,29 @@ static ListeningAddress waitForCapturedListeningData(Process quarkusProcess, Pat } } + /** + * Try to destroy the process normally a few times + * and resort to forceful destruction if necessary + */ + private static void destroyProcess(Process quarkusProcess) { + quarkusProcess.destroy(); + int i = 0; + while (i++ < 10) { + try { + Thread.sleep(500); + } catch (InterruptedException ignored) { + + } + if (!quarkusProcess.isAlive()) { + break; + } + } + + if (quarkusProcess.isAlive()) { + quarkusProcess.destroyForcibly(); + } + } + /** * Updates the configuration necessary to make all test systems knowledgeable about the port on which the launched * process is listening