Skip to content

Commit d35bc4d

Browse files
authored
Merge pull request #47426 from holly-cummins/handle-tccl-setting-for-method-source
Only reset the test TCCL in cases where we had changed it
2 parents e09cf64 + 8cd3121 commit d35bc4d

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

integration-tests/main/src/test/java/io/quarkus/it/main/MethodSourceTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import jakarta.inject.Inject;
1010

11+
import org.eclipse.microprofile.config.ConfigProvider;
1112
import org.hamcrest.CoreMatchers;
1213
import org.hamcrest.Matcher;
1314
import org.junit.jupiter.params.ParameterizedTest;
@@ -28,6 +29,9 @@ public class MethodSourceTest {
2829
public void testParameterResolver(UnusedBean.DummyInput dummyInput, Matcher<String> matcher) {
2930
UnusedBean.DummyResult dummyResult = unusedBean.dummy(dummyInput);
3031
assertThat(dummyResult.getResult(), matcher);
32+
33+
// Can we get config?
34+
ConfigProvider.getConfig();
3135
}
3236

3337
private static Collection<Arguments> provideDummyInput() {

integration-tests/maven/pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@
7474
<artifactId>quarkus-vertx-http-dev-ui-tests</artifactId>
7575
<scope>test</scope>
7676
</dependency>
77+
<!-- This one is used by the tested projects so we need to create a dependency
78+
to make sure GIB triggers the testing. -->
79+
<dependency>
80+
<groupId>io.quarkus</groupId>
81+
<artifactId>quarkus-junit5</artifactId>
82+
<scope>test</scope>
83+
<version>${project.version}</version>
84+
</dependency>
7785
<dependency>
7886
<groupId>io.quarkus</groupId>
7987
<artifactId>quarkus-project-core-extension-codestarts</artifactId>

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

+11-7
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ public void executionStarted(TestIdentifier testIdentifier) {
2525
Optional<TestSource> oSource = testIdentifier.getSource();
2626
if (oSource.isPresent()) {
2727
TestSource source = oSource.get();
28-
if (source instanceof ClassSource) {
29-
ClassSource cs = (ClassSource) source;
28+
if (source instanceof ClassSource cs) {
3029
ClassLoader classLoader = cs.getJavaClass().getClassLoader();
3130
// Only adjust the TCCL in cases where we know the QuarkusTestExtension would be about to do it anyway
3231
// We could check annotations, but that would be slow, and the assumption that only Quarkus Tests are loaded with the quarkus classloader should be a fair one
3332
if (classLoader instanceof QuarkusClassLoader) {
34-
origCl = Thread.currentThread()
35-
.getContextClassLoader();
33+
origCl = Thread.currentThread().getContextClassLoader();
3634
Thread.currentThread().setContextClassLoader(classLoader);
3735
} else {
3836
origCl = null;
@@ -43,9 +41,15 @@ public void executionStarted(TestIdentifier testIdentifier) {
4341

4442
@Override
4543
public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult result) {
46-
if (origCl != null) {
47-
// If execution is parallel this could be odd, but if execution is parallel any kind of TCCL manipulation will be ill-fated
48-
Thread.currentThread().setContextClassLoader(origCl);
44+
Optional<TestSource> oSource = testIdentifier.getSource();
45+
if (oSource.isPresent()) {
46+
TestSource source = oSource.get();
47+
if (source instanceof ClassSource) {
48+
if (origCl != null) {
49+
// If execution is parallel this could produce odd results, but if execution is parallel any kind of TCCL manipulation will be ill-fated
50+
Thread.currentThread().setContextClassLoader(origCl);
51+
}
52+
}
4953
}
5054
}
5155
}

0 commit comments

Comments
 (0)