From 71804ebd709e39c11eb35116e68b8fca8aefe41d Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Fri, 22 Nov 2024 10:38:12 +0200 Subject: [PATCH] Clean up effects of test profiles when @QuarkusMainTest completes Fixes: #44117 --- .../test/junit/QuarkusMainTestExtension.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java index 107c2f9b60b81..7975bd7b1b18d 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java @@ -43,6 +43,7 @@ public class QuarkusMainTestExtension extends AbstractJvmQuarkusTestExtension AfterAllCallback, ExecutionCondition { PrepareResult prepareResult; + LinkedBlockingDeque shutdownTasks; /** * The result from an {@link Launch} test @@ -79,9 +80,8 @@ private void ensurePrepared(ExtensionContext extensionContext, Class shutdownTasks = new LinkedBlockingDeque<>(); - PrepareResult result = createAugmentor(extensionContext, profile, shutdownTasks); - prepareResult = result; + shutdownTasks = new LinkedBlockingDeque<>(); + prepareResult = createAugmentor(extensionContext, profile, shutdownTasks); } } @@ -318,6 +318,17 @@ private boolean isIntegrationTest(Class clazz) { @Override public void afterAll(ExtensionContext context) throws Exception { currentTestClassStack.pop(); + + try { + if (shutdownTasks != null) { + for (Runnable shutdownTask : shutdownTasks) { + shutdownTask.run(); + } + } + shutdownTasks = null; + } catch (Exception e) { + System.err.println("Unable to run shutdown tasks: " + e.getMessage()); + } } @Override