Skip to content

Commit 97ada7c

Browse files
Merge pull request #48298 from holly-cummins/tolerate-eclipse-for-integration-tests
Do not set TCCL if there is unlikely to be a discovery phase to close it
2 parents 93cb613 + 514a5f9 commit 97ada7c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/CustomLauncherInterceptor.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class CustomLauncherInterceptor implements LauncherDiscoveryListener, Lau
1212
private static FacadeClassLoader facadeLoader = null;
1313
// Also use a static variable to store a 'first' starting state that we can reset to
1414
private static ClassLoader origCl = null;
15+
private static boolean discoveryStarted = false;
1516

1617
public CustomLauncherInterceptor() {
1718
}
@@ -25,10 +26,18 @@ private static boolean isProductionModeTests() {
2526
public void launcherSessionOpened(LauncherSession session) {
2627
/*
2728
* For gradle, test class loading happens fairly shortly after this is called,
28-
* before the formal discovery phase. So we need to intercept the TCCL
29-
* Do not do any classloading dance for prod mode tests;
29+
* before the formal discovery phase. So we need to intercept the TCCL.
30+
*
31+
* However, the Eclipse runner calls this twice, and the second invocation happens after discovery,
32+
* which means there is no one to unset the TCCL. That breaks integration tests, so we
33+
* need to add an ugly guard to not adjust the TCCL the second time round in that scenario.
34+
* We do not do any classloading dance for prod mode tests.
3035
*/
31-
if (!isProductionModeTests()) {
36+
boolean isEclipse = System.getProperty("sun.java.command") != null
37+
&& System.getProperty("sun.java.command").contains("JUnit5TestLoader");
38+
boolean shouldSkipSettingTCCL = isEclipse && discoveryStarted;
39+
40+
if (!isProductionModeTests() && !shouldSkipSettingTCCL) {
3241
actuallyIntercept();
3342
}
3443

@@ -67,6 +76,7 @@ private void initializeFacadeClassLoader() {
6776

6877
@Override
6978
public void launcherDiscoveryStarted(LauncherDiscoveryRequest request) {
79+
discoveryStarted = true;
7080
// If anything comes through this method for which there are non-null classloaders on the selectors, that will bypass our classloading
7181
// To check that case, the code would be something like this. We could detect and warn early, and possibly even filter that test out, but that's not necessarily a better UX than failing later
7282
// request.getSelectorsByType(ClassSelector.class).stream().map(ClassSelector::getClassLoader) ... and then check for non-emptiness on that field

0 commit comments

Comments
 (0)