Skip to content

[SUREFIRE-1643] surefire junit5 parallel tests #815

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

Merged
merged 28 commits into from
Mar 23, 2025
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9385ee5
[SUREFIRE-1643] Make surefire junit5 supporting parallel execution an…
olamy Mar 16, 2025
584fcd6
java 21
olamy Mar 16, 2025
81bf277
fix typo
olamy Mar 16, 2025
296e96a
build with mvn 3.8.8
olamy Mar 16, 2025
72b1c8a
avoid NPE
olamy Mar 16, 2025
36bdc88
use getName if no sourceName
olamy Mar 16, 2025
f59cc1d
restore backward compat
olamy Mar 17, 2025
d2e7858
simplify jenkinsfile
olamy Mar 17, 2025
8e24d2c
comment
olamy Mar 17, 2025
8b1ee72
comment
olamy Mar 17, 2025
0f2e788
ignore no sense test
olamy Mar 17, 2025
74dc32c
do not use LegacyXmlReportGeneratingListener for junit5
olamy Mar 17, 2025
ebc4ee9
[SUREFIRE-1643] fix backward compatibility with other providers
olamy Mar 17, 2025
2123b2e
ignore possible flaky test
olamy Mar 17, 2025
7995ebc
upgrade to last mockito supporting java8 and fix mockito usage
olamy Mar 18, 2025
2b1f9c2
use more nodes
olamy Mar 18, 2025
1c36c16
relax this performance test
olamy Mar 18, 2025
6a27e38
Test IT test for SUREFIRE-1643
olamy Mar 18, 2025
1ca4df9
[SUREFIRE-1643] fix plumbing
olamy Mar 19, 2025
e6fe26c
dependency not needed
olamy Mar 19, 2025
c26e98d
remove not needed change
olamy Mar 19, 2025
c41541f
remove not needed change
olamy Mar 19, 2025
92cb07b
test with default forknode impl
olamy Mar 19, 2025
5c7e738
fix last it
olamy Mar 20, 2025
c481a99
reduce number of ITS threads running in parallel
olamy Mar 20, 2025
ae50321
remove useless docck-maven-plugin
olamy Mar 20, 2025
7402d84
fix version in IT file
olamy Mar 20, 2025
cced9cd
restore a core version we do not even support anymore
olamy Mar 20, 2025
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
15 changes: 7 additions & 8 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@

properties(
[
buildDiscarder(logRotator(artifactDaysToKeepStr: env.BRANCH_NAME == 'master' ? '14' : '7',
artifactNumToKeepStr: '50',
buildDiscarder(logRotator(artifactNumToKeepStr: env.BRANCH_NAME == 'master' ? '15' : '5',
daysToKeepStr: env.BRANCH_NAME == 'master' ? '30' : '14',
numToKeepStr: env.BRANCH_NAME == 'master' ? '20' : '10')
),
disableConcurrentBuilds()
)//,
//disableConcurrentBuilds()
]
)
// final def oses = ['linux':'ubuntu && maven', 'windows':'windows-he']
final def oses = ['linux':'ubuntu && maven']
final def mavens = env.BRANCH_NAME == 'master' ? ['3.x.x', '3.6.3'] : ['3.x.x']
final def oses = ['linux':'ubuntu']
final def mavens = env.BRANCH_NAME == 'master' ? ['3.x.x', '3.8.8'] : ['3.x.x']
// all non-EOL versions and the first EA
final def jdks = [20, 17, 11, 8]
final def jdks = [21, 17, 11, 8]

final def options = ['-e', '-V', '-B', '-nsu', '-P', 'run-its']
final def goals = ['clean', 'install']
Expand Down Expand Up @@ -134,7 +133,7 @@ def buildProcess(String stageKey, String jdkName, String mvnName, goals, options
println "Maven Local Repository = ${mvnLocalRepoDir}."
assert mvnLocalRepoDir != null : 'Local Maven Repository is undefined.'

def properties = ["-Djacoco.skip=${!makeReports}", "\"-Dmaven.repo.local=${mvnLocalRepoDir}\""]
def properties = ["-Papache.ci -Djacoco.skip=${!makeReports}", "\"-Dmaven.repo.local=${mvnLocalRepoDir}\""]
def cmd = ['mvn'] + goals + options + properties

stage("build ${stageKey}") {
Expand Down
24 changes: 0 additions & 24 deletions maven-failsafe-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,30 +233,6 @@
</reporting>

<profiles>
<profile>
<id>ci</id>
<activation>
<property>
<name>enableCiProfile</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-docck-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>run-its</id>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.apache.maven.surefire.api.booter.Shutdown;
import org.apache.maven.surefire.api.cli.CommandLineOption;
import org.apache.maven.surefire.api.report.ReporterConfiguration;
import org.apache.maven.surefire.api.report.ReporterFactoryOptions;
import org.apache.maven.surefire.api.suite.RunResult;
import org.apache.maven.surefire.api.testset.DirectoryScannerParameters;
import org.apache.maven.surefire.api.testset.RunOrderParameters;
Expand Down Expand Up @@ -2056,7 +2057,8 @@ private Artifact getShadefireArtifact() {
return getPluginArtifactMap().get("org.apache.maven.surefire:surefire-shadefire");
}

private StartupReportConfiguration getStartupReportConfiguration(String configChecksum, boolean isForking) {
private StartupReportConfiguration getStartupReportConfiguration(
String configChecksum, boolean isForking, ProviderInfo providerInfo) {
SurefireStatelessReporter xmlReporter =
statelessTestsetReporter == null ? new SurefireStatelessReporter() : statelessTestsetReporter;

Expand All @@ -2071,6 +2073,11 @@ private StartupReportConfiguration getStartupReportConfiguration(String configCh
? new SurefireStatelessTestsetInfoReporter()
: statelessTestsetInfoReporter;

// SUREFIRE-1643 we can force this here as junit5 will need this for multi thread test
ReporterFactoryOptions reporterFactoryOptions = new ReporterFactoryOptions();
if ("org.apache.maven.surefire.junitplatform.JUnitPlatformProvider".equals(providerInfo.getProviderName())) {
reporterFactoryOptions.setStatPerSourceName(true);
}
return new StartupReportConfiguration(
isUseFile(),
isPrintSummary(),
Expand All @@ -2089,7 +2096,8 @@ private StartupReportConfiguration getStartupReportConfiguration(String configCh
isEnablePropertiesElement(),
xmlReporter,
outReporter,
testsetReporter);
testsetReporter,
reporterFactoryOptions);
}

private boolean isSpecificTestSpecified() {
Expand Down Expand Up @@ -2317,7 +2325,9 @@ private ForkStarter createForkStarter(
platform,
resolvedJavaModularityResult);
String configChecksum = getConfigChecksum();
StartupReportConfiguration startupReportConfiguration = getStartupReportConfiguration(configChecksum, true);
StartupReportConfiguration startupReportConfiguration =
getStartupReportConfiguration(configChecksum, true, provider);

ProviderConfiguration providerConfiguration = createProviderConfiguration(runOrderParameters);
return new ForkStarter(
providerConfiguration,
Expand Down Expand Up @@ -2345,7 +2355,8 @@ private InPluginVMSurefireStarter createInprocessStarter(
platform,
new ResolvePathResultWrapper(null, true));
String configChecksum = getConfigChecksum();
StartupReportConfiguration startupReportConfiguration = getStartupReportConfiguration(configChecksum, false);
StartupReportConfiguration startupReportConfiguration =
getStartupReportConfiguration(configChecksum, false, provider);
ProviderConfiguration providerConfiguration = createProviderConfiguration(runOrderParameters);
return new InPluginVMSurefireStarter(
startupConfiguration, providerConfiguration, startupReportConfiguration, getConsoleLogger(), platform);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.plugin.surefire.log.api.ConsoleLoggerDecorator;
import org.apache.maven.plugin.surefire.report.DefaultReporterFactory;
import org.apache.maven.surefire.api.report.ReporterFactoryOptions;
import org.apache.maven.surefire.api.util.SurefireReflectionException;

import static org.apache.maven.surefire.api.util.ReflectionUtils.getConstructor;
Expand All @@ -44,6 +45,7 @@ public class CommonReflector {
private final Class<?> statelessTestsetReporter;
private final Class<?> consoleOutputReporter;
private final Class<?> statelessTestsetInfoReporter;
private final Class<?> reporterFactoryOptions;
private final ClassLoader surefireClassLoader;

public CommonReflector(@Nonnull ClassLoader surefireClassLoader) {
Expand All @@ -56,6 +58,7 @@ public CommonReflector(@Nonnull ClassLoader surefireClassLoader) {
consoleOutputReporter = surefireClassLoader.loadClass(SurefireConsoleOutputReporter.class.getName());
statelessTestsetInfoReporter =
surefireClassLoader.loadClass(SurefireStatelessTestsetInfoReporter.class.getName());
reporterFactoryOptions = surefireClassLoader.loadClass(ReporterFactoryOptions.class.getName());
} catch (ClassNotFoundException e) {
throw new SurefireReflectionException(e);
}
Expand Down Expand Up @@ -90,7 +93,8 @@ private Object createStartupReportConfiguration(@Nonnull StartupReportConfigurat
boolean.class,
statelessTestsetReporter,
consoleOutputReporter,
statelessTestsetInfoReporter);
statelessTestsetInfoReporter,
reporterFactoryOptions);
Object[] params = {
reporterConfiguration.isUseFile(),
reporterConfiguration.isPrintSummary(),
Expand All @@ -109,7 +113,8 @@ private Object createStartupReportConfiguration(@Nonnull StartupReportConfigurat
reporterConfiguration.isEnablePropertiesElement(),
reporterConfiguration.getXmlReporter().clone(surefireClassLoader),
reporterConfiguration.getConsoleOutputReporter().clone(surefireClassLoader),
reporterConfiguration.getTestsetReporter().clone(surefireClassLoader)
reporterConfiguration.getTestsetReporter().clone(surefireClassLoader),
reporterConfiguration.getReporterFactoryOptions().clone(surefireClassLoader)
};
return newInstance(constructor, params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.maven.plugin.surefire.report.TestSetStats;
import org.apache.maven.plugin.surefire.report.WrappedReportEntry;
import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
import org.apache.maven.surefire.api.report.ReporterFactoryOptions;
import org.apache.maven.surefire.extensions.ConsoleOutputReportEventListener;
import org.apache.maven.surefire.extensions.StatelessReportEventListener;
import org.apache.maven.surefire.extensions.StatelessTestsetInfoConsoleReportEventListener;
Expand Down Expand Up @@ -97,6 +98,8 @@ public final class StartupReportConfiguration {

private StatisticsReporter statisticsReporter;

private final ReporterFactoryOptions reporterFactoryOptions;

/**
* @since 3.3.1
*/
Expand All @@ -119,7 +122,8 @@ public StartupReportConfiguration(
boolean enablePropertiesElement,
SurefireStatelessReporter xmlReporter,
SurefireConsoleOutputReporter consoleOutputReporter,
SurefireStatelessTestsetInfoReporter testsetReporter) {
SurefireStatelessTestsetInfoReporter testsetReporter,
ReporterFactoryOptions reporterFactoryOptions) {
this.useFile = useFile;
this.printSummary = printSummary;
this.reportFormat = reportFormat;
Expand All @@ -141,6 +145,7 @@ public StartupReportConfiguration(
this.xmlReporter = xmlReporter;
this.consoleOutputReporter = consoleOutputReporter;
this.testsetReporter = testsetReporter;
this.reporterFactoryOptions = reporterFactoryOptions;
}

@SuppressWarnings("checkstyle:parameternumber")
Expand Down Expand Up @@ -180,7 +185,8 @@ public StartupReportConfiguration(
true,
xmlReporter,
consoleOutputReporter,
testsetReporter);
testsetReporter,
new ReporterFactoryOptions(false));
}

public boolean isUseFile() {
Expand Down Expand Up @@ -220,7 +226,7 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> instantiat
// In the in-plugin execution of parallel JUnit4.7 with rerun the map must be shared because reports and
// listeners are in ThreadLocal, see Surefire1122ParallelAndFlakyTestsIT.
Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory =
isForking ? new ConcurrentHashMap<String, Deque<WrappedReportEntry>>() : this.testClassMethodRunHistory;
isForking ? new ConcurrentHashMap<>() : this.testClassMethodRunHistory;

DefaultStatelessReportMojoConfiguration xmlReporterConfig = new DefaultStatelessReportMojoConfiguration(
resolveReportsDirectory(forkNumber),
Expand Down Expand Up @@ -319,4 +325,8 @@ public SurefireStatelessTestsetInfoReporter getTestsetReporter() {
private boolean shouldReportToConsole() {
return isUseFile() ? isPrintSummary() : isRedirectTestOutputToFile() || isBriefOrPlainFormat();
}

public ReporterFactoryOptions getReporterFactoryOptions() {
return reporterFactoryOptions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public TestReportListener<TestOutputReportEntry> createTestReportListener() {
reportConfiguration.isTrimStackTrace(),
PLAIN.equals(reportConfiguration.getReportFormat()),
reportConfiguration.isBriefOrPlainFormat(),
consoleLogger);
consoleLogger,
reportConfiguration.getReporterFactoryOptions().isStatPerSourceName());
addListener(testSetRunListener);
return testSetRunListener;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -392,7 +392,7 @@ private OutputStream getOutputStream(WrappedReportEntry testSetReportEntry) thro
reportFile.delete();
//noinspection ResultOfMethodCallIgnored
reportDir.mkdirs();
return new BufferedOutputStream(new FileOutputStream(reportFile), 64 * 1024);
return new BufferedOutputStream(Files.newOutputStream(reportFile.toPath()), 64 * 1024);
}

private static OutputStreamWriter getWriter(OutputStream fos) {
Expand Down
Loading
Loading