From 3df1ea233e059a7c6b9914e06647dc4f48de7886 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sat, 30 Nov 2024 15:50:35 +0000 Subject: [PATCH 1/2] Handle multiple FabricLoaderLauncherSessionListener instances. It seems that the VSCode test runner will create multiple FabricLoaderLauncherSessionListener instances. We can only ever have one Knot instance so store it statically. --- build.gradle | 2 +- junit/build.gradle | 2 +- .../junit/FabricLoaderLauncherSessionListener.java | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 238aa59e7..345ca5640 100644 --- a/build.gradle +++ b/build.gradle @@ -127,7 +127,7 @@ dependencies { testImplementation('org.junit.jupiter:junit-jupiter:5.9.2') testRuntimeOnly('org.junit.platform:junit-platform-launcher') - testImplementation("org.mockito:mockito-core:5.10.0") + testImplementation("org.mockito:mockito-core:5.11.3") } apply from: rootProject.file('gradle/installer-json.gradle') diff --git a/junit/build.gradle b/junit/build.gradle index 656f23456..6b2b8ae9a 100644 --- a/junit/build.gradle +++ b/junit/build.gradle @@ -18,7 +18,7 @@ repositories { dependencies { api project(":") - api platform("org.junit:junit-bom:5.10.0") + api platform("org.junit:junit-bom:5.11.3") api "org.junit.jupiter:junit-jupiter-engine" implementation "org.junit.platform:junit-platform-launcher" } diff --git a/junit/src/main/java/net/fabricmc/loader/impl/junit/FabricLoaderLauncherSessionListener.java b/junit/src/main/java/net/fabricmc/loader/impl/junit/FabricLoaderLauncherSessionListener.java index 102847f4c..827e2738c 100644 --- a/junit/src/main/java/net/fabricmc/loader/impl/junit/FabricLoaderLauncherSessionListener.java +++ b/junit/src/main/java/net/fabricmc/loader/impl/junit/FabricLoaderLauncherSessionListener.java @@ -31,12 +31,20 @@ public class FabricLoaderLauncherSessionListener implements LauncherSessionListe System.setProperty(SystemProperties.UNIT_TEST, "true"); } - private final Knot knot; - private final ClassLoader classLoader; + private static Knot knot = null; + private static ClassLoader classLoader = null; private ClassLoader launcherSessionClassLoader; public FabricLoaderLauncherSessionListener() { + setup(); + } + + private synchronized static void setup() { + if (knot != null) { + return; + } + final Thread currentThread = Thread.currentThread(); final ClassLoader originalClassLoader = currentThread.getContextClassLoader(); From fbf5860c9317f06ead02071a44a46a4b6f135226 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sat, 30 Nov 2024 15:55:11 +0000 Subject: [PATCH 2/2] Fix --- build.gradle | 2 +- .../loader/impl/junit/FabricLoaderLauncherSessionListener.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 345ca5640..238aa59e7 100644 --- a/build.gradle +++ b/build.gradle @@ -127,7 +127,7 @@ dependencies { testImplementation('org.junit.jupiter:junit-jupiter:5.9.2') testRuntimeOnly('org.junit.platform:junit-platform-launcher') - testImplementation("org.mockito:mockito-core:5.11.3") + testImplementation("org.mockito:mockito-core:5.10.0") } apply from: rootProject.file('gradle/installer-json.gradle') diff --git a/junit/src/main/java/net/fabricmc/loader/impl/junit/FabricLoaderLauncherSessionListener.java b/junit/src/main/java/net/fabricmc/loader/impl/junit/FabricLoaderLauncherSessionListener.java index 827e2738c..fa2d3ce14 100644 --- a/junit/src/main/java/net/fabricmc/loader/impl/junit/FabricLoaderLauncherSessionListener.java +++ b/junit/src/main/java/net/fabricmc/loader/impl/junit/FabricLoaderLauncherSessionListener.java @@ -40,7 +40,7 @@ public FabricLoaderLauncherSessionListener() { setup(); } - private synchronized static void setup() { + private static synchronized void setup() { if (knot != null) { return; }