Skip to content

Leave the TCCL how we found it after test discovery #47365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ public Runnable prepare() {
LogCapturingOutputFilter logHandler = new LogCapturingOutputFilter(testApplication, true, true,
TestSupport.instance()
.get()::isDisplayTestOutput);
// TODO do we want to do this setting of the TCCL? I think it just makes problems?
Thread.currentThread().setContextClassLoader(tcl);

System.out.println("HOLLY TCCL watch 1 " + Thread.currentThread().getContextClassLoader());
Set<UniqueId> allDiscoveredIds = new HashSet<>();
Set<UniqueId> dynamicIds = new HashSet<>();
DiscoveryResult quarkusTestClasses = discoverTestClasses();
System.out.println("HOLLY TCCL watch 2 " + Thread.currentThread().getContextClassLoader());

Launcher launcher = LauncherFactory.create(LauncherConfig.builder().build());
LauncherDiscoveryRequestBuilder launchBuilder = LauncherDiscoveryRequestBuilder.request()
Expand Down Expand Up @@ -211,7 +211,12 @@ public FilterResult apply(TestDescriptor testDescriptor) {

LauncherDiscoveryRequest request = launchBuilder
.build();
System.out.println("HOLLY TCCL watch 2a " + Thread.currentThread().getContextClassLoader());
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
TestPlan testPlan = launcher.discover(request);
System.out.println("HOLLY TCCL watch 3 " + Thread.currentThread().getContextClassLoader());
Thread.currentThread().setContextClassLoader(deploymentClassLoader);
System.out.println("HOLLY TCCL watch 4 " + Thread.currentThread().getContextClassLoader());
long toRun = testPlan.countTestIdentifiers(TestIdentifier::isTest);
for (TestRunListener listener : listeners) {
listener.runStarted(toRun);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,39 @@ public void testQuarkusTestInMetaInfServicesNormalTesting()

}

@Disabled("Not working, see https://github.com/quarkusio/quarkus/issues/47364")
@Test
public void testQuarkusTestGuardedByConditionContinuousTesting()
throws MavenInvocationException, FileNotFoundException {
//we also check continuous testing
String sourceDir = "projects/test-test-conditions";
testDir = initProject(sourceDir, sourceDir + "-processed-devmode");

runAndCheck();

ContinuousTestingMavenTestUtils testingTestUtils = new ContinuousTestingMavenTestUtils(getPort());
ContinuousTestingMavenTestUtils.TestStatus results = testingTestUtils.waitForNextCompletion();
// This is a bit brittle when we add tests, but failures are often so catastrophic they're not even reported as failures,
// so we need to check the pass count explicitly
Assertions.assertEquals(0, results.getTestsFailed());
Assertions.assertEquals(1, results.getTestsPassed());
}

@Test
public void testQuarkusTestGuardedByCondition()
throws MavenInvocationException, InterruptedException {
String sourceDir = "projects/test-test-conditions";
testDir = initProject(sourceDir, sourceDir + "-processed");
RunningInvoker invoker = new RunningInvoker(testDir, false);

// to properly surface the problem of multiple classpath entries, we need to install the project to the local m2
MavenProcessInvocationResult installInvocation = invoker.execute(
List.of("clean", "verify", "-Dquarkus.analytics.disabled=true"),
Collections.emptyMap());
assertThat(installInvocation.getProcess().waitFor(2, TimeUnit.MINUTES)).isTrue();
assertThat(installInvocation.getExecutionException()).isNull();
assertThat(installInvocation.getExitCode()).isEqualTo(0);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>

<groupId>org.acme</groupId>
<artifactId>quarkus-test-test-profile</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.version>@project.version@</quarkus.platform.version>
<quarkus-plugin.version>@project.version@</quarkus-plugin.version>
<compiler-plugin.version>${compiler-plugin.version}</compiler-plugin.version>
<surefire-plugin.version>${version.surefire.plugin}</surefire-plugin.version>
<maven.compiler.source>${maven.compiler.source}</maven.compiler.source>
<maven.compiler.target>${maven.compiler.target}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>\${quarkus.platform.group-id}</groupId>
<artifactId>\${quarkus.platform.artifact-id}</artifactId>
<version>\${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>\${surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>\${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>\${quarkus-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>


<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<quarkus.native.enabled>true</quarkus.native.enabled>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>\${native.surefire.skip}</skipTests>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>\${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>\${project.build.directory}/\${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>\${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.acme;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/hello")
public class HelloResource {


@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.acme;

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

@ApplicationPath("/app")
public class MyApplication extends Application {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>acme - 1.0-SNAPSHOT</title>
<style>
h1, h2, h3, h4, h5, h6 {
margin-bottom: 0.5rem;
font-weight: 400;
line-height: 1.5;
}

h1 {
font-size: 2.5rem;
}

h2 {
font-size: 2rem
}

h3 {
font-size: 1.75rem
}

h4 {
font-size: 1.5rem
}

h5 {
font-size: 1.25rem
}

h6 {
font-size: 1rem
}

.lead {
font-weight: 300;
font-size: 2rem;
}

.banner {
font-size: 2.7rem;
margin: 0;
padding: 2rem 1rem;
background-color: #00A1E2;
color: white;
}

body {
margin: 0;
font-family: -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

code {
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
font-size: 87.5%;
color: #e83e8c;
word-break: break-word;
}

.left-column {
padding: .75rem;
max-width: 75%;
min-width: 55%;
}

.right-column {
padding: .75rem;
max-width: 25%;
}

.container {
display: flex;
width: 100%;
}

li {
margin: 0.75rem;
}

.right-section {
margin-left: 1rem;
padding-left: 0.5rem;
}

.right-section h3 {
padding-top: 0;
font-weight: 200;
}

.right-section ul {
border-left: 0.3rem solid #00A1E2;
list-style-type: none;
padding-left: 0;
}

</style>
</head>
<body>

<div class="banner lead">
Your new Cloud-Native application is ready!
</div>

<div class="container">
<div class="left-column">
<p class="lead"> Congratulations, you have created a new Quarkus application.</p>

<h2>Why do you see this?</h2>

<p>This page is served by Quarkus. The source is in
<code>src/main/resources/META-INF/resources/index.html</code>.</p>

<h2>What can I do from here?</h2>

<p>If not already done, run the application in <em>dev mode</em> using: <code>mvn quarkus:dev</code>.
</p>
<ul>
<li>Add REST resources, Servlets, functions and other services in <code>src/main/java</code>.</li>
<li>Your static assets are located in <code>src/main/resources/META-INF/resources</code>.</li>
<li>Configure your application in <code>src/main/resources/application.properties</code>.
</li>
</ul>

<h2>Do you like Quarkus?</h2>
<p>Go give it a star on <a href="https://github.com/quarkusio/quarkus">GitHub</a>.</p>

<h2>How do I get rid of this page?</h2>
<p>Just delete the <code>src/main/resources/META-INF/resources/index.html</code> file.</p>
</div>
<div class="right-column">
<div class="right-section">
<h3>Application</h3>
<ul>
<li>GroupId: org.acme</li>
<li>ArtifactId: acme</li>
<li>Version: 1.0-SNAPSHOT</li>
<li>Quarkus Version: 999-SNAPSHOT</li>
</ul>
</div>
<div class="right-section">
<h3>Next steps</h3>
<ul>
<!-- the url have been erased on purpose -->
<li><a href="#">Setup your IDE</a></li>
<li><a href="#">Getting started</a></li>
<li><a href="#">Documentation</a></li>
</ul>
</div>
</div>
</div>


</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quarkus.test.continuous-testing=enabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.acme;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.extension.ExtendWith;

@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@ExtendWith(AlwaysEnabledCondition.class)
public @interface AlwaysEnabled {
}
Loading
Loading