From 9553d795404d02f4a3f3350bd45aa4e2a883029c Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 16 Jun 2021 18:37:51 +0300 Subject: [PATCH] Fix QuarkusClassLoader leak in QuarkusProdModeTest This could result in the tests either hanging or the process dying because of insufficient metaspace --- .../io/quarkus/test/QuarkusProdModeTest.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusProdModeTest.java b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusProdModeTest.java index 9d152c8082623..2a6b619ec019e 100644 --- a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusProdModeTest.java +++ b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusProdModeTest.java @@ -312,20 +312,7 @@ public void beforeAll(ExtensionContext extensionContext) throws Exception { originalHandlers = rootLogger.getHandlers(); rootLogger.addHandler(inMemoryLogHandler); - timeoutTask = new TimerTask() { - @Override - public void run() { - System.err.println("Test has been running for more than 5 minutes, thread dump is:"); - for (Map.Entry i : Thread.getAllStackTraces().entrySet()) { - System.err.println("\n"); - System.err.println(i.toString()); - System.err.println("\n"); - for (StackTraceElement j : i.getValue()) { - System.err.println(j); - } - } - } - }; + timeoutTask = new PrintStackTraceTimerTask(); timeoutTimer.schedule(timeoutTask, 1000 * 60 * 5); ExtensionContext.Store store = extensionContext.getRoot().getStore(ExtensionContext.Namespace.GLOBAL); @@ -638,6 +625,7 @@ public void afterAll(ExtensionContext extensionContext) throws Exception { try { if (curatedApplication != null) { curatedApplication.close(); + curatedApplication = null; } } finally { timeoutTask.cancel(); @@ -699,4 +687,18 @@ public QuarkusProdModeTest setCommandLineParameters(String... commandLineParamet return this; } + private static class PrintStackTraceTimerTask extends TimerTask { + @Override + public void run() { + System.err.println("Test has been running for more than 5 minutes, thread dump is:"); + for (Map.Entry i : Thread.getAllStackTraces().entrySet()) { + System.err.println("\n"); + System.err.println(i.toString()); + System.err.println("\n"); + for (StackTraceElement j : i.getValue()) { + System.err.println(j); + } + } + } + } }