Skip to content

Commit 5aeca19

Browse files
authored
[SUREFIRE-1643] surefire junit5 parallel tests (#815)
* [SUREFIRE-1643] Make surefire junit5 supporting parallel execution and not mixing result when re running tests --------- Signed-off-by: Olivier Lamy <[email protected]>
1 parent c730ad0 commit 5aeca19

File tree

37 files changed

+555
-146
lines changed

37 files changed

+555
-146
lines changed

Jenkinsfile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,18 @@
2121

2222
properties(
2323
[
24-
buildDiscarder(logRotator(artifactDaysToKeepStr: env.BRANCH_NAME == 'master' ? '14' : '7',
25-
artifactNumToKeepStr: '50',
24+
buildDiscarder(logRotator(artifactNumToKeepStr: env.BRANCH_NAME == 'master' ? '15' : '5',
2625
daysToKeepStr: env.BRANCH_NAME == 'master' ? '30' : '14',
2726
numToKeepStr: env.BRANCH_NAME == 'master' ? '20' : '10')
28-
),
29-
disableConcurrentBuilds()
27+
)//,
28+
//disableConcurrentBuilds()
3029
]
3130
)
3231
// final def oses = ['linux':'ubuntu && maven', 'windows':'windows-he']
33-
final def oses = ['linux':'ubuntu && maven']
32+
final def oses = ['linux':'ubuntu']
3433
final def mavens = env.BRANCH_NAME == 'master' ? ['3.x.x', '3.6.3'] : ['3.x.x']
3534
// all non-EOL versions and the first EA
36-
final def jdks = [20, 17, 11, 8]
35+
final def jdks = [21, 17, 11, 8]
3736

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

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

140139
stage("build ${stageKey}") {

maven-failsafe-plugin/pom.xml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -233,30 +233,6 @@
233233
</reporting>
234234

235235
<profiles>
236-
<profile>
237-
<id>ci</id>
238-
<activation>
239-
<property>
240-
<name>enableCiProfile</name>
241-
<value>true</value>
242-
</property>
243-
</activation>
244-
<build>
245-
<plugins>
246-
<plugin>
247-
<artifactId>maven-docck-plugin</artifactId>
248-
<version>1.2</version>
249-
<executions>
250-
<execution>
251-
<goals>
252-
<goal>check</goal>
253-
</goals>
254-
</execution>
255-
</executions>
256-
</plugin>
257-
</plugins>
258-
</build>
259-
</profile>
260236
<profile>
261237
<id>run-its</id>
262238
<build>

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import org.apache.maven.surefire.api.booter.Shutdown;
8686
import org.apache.maven.surefire.api.cli.CommandLineOption;
8787
import org.apache.maven.surefire.api.report.ReporterConfiguration;
88+
import org.apache.maven.surefire.api.report.ReporterFactoryOptions;
8889
import org.apache.maven.surefire.api.suite.RunResult;
8990
import org.apache.maven.surefire.api.testset.DirectoryScannerParameters;
9091
import org.apache.maven.surefire.api.testset.RunOrderParameters;
@@ -2056,7 +2057,8 @@ private Artifact getShadefireArtifact() {
20562057
return getPluginArtifactMap().get("org.apache.maven.surefire:surefire-shadefire");
20572058
}
20582059

2059-
private StartupReportConfiguration getStartupReportConfiguration(String configChecksum, boolean isForking) {
2060+
private StartupReportConfiguration getStartupReportConfiguration(
2061+
String configChecksum, boolean isForking, ProviderInfo providerInfo) {
20602062
SurefireStatelessReporter xmlReporter =
20612063
statelessTestsetReporter == null ? new SurefireStatelessReporter() : statelessTestsetReporter;
20622064

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

2076+
// SUREFIRE-1643 we can force this here as junit5 will need this for multi thread test
2077+
ReporterFactoryOptions reporterFactoryOptions = new ReporterFactoryOptions();
2078+
if ("org.apache.maven.surefire.junitplatform.JUnitPlatformProvider".equals(providerInfo.getProviderName())) {
2079+
reporterFactoryOptions.setStatPerSourceName(true);
2080+
}
20742081
return new StartupReportConfiguration(
20752082
isUseFile(),
20762083
isPrintSummary(),
@@ -2089,7 +2096,8 @@ private StartupReportConfiguration getStartupReportConfiguration(String configCh
20892096
isEnablePropertiesElement(),
20902097
xmlReporter,
20912098
outReporter,
2092-
testsetReporter);
2099+
testsetReporter,
2100+
reporterFactoryOptions);
20932101
}
20942102

20952103
private boolean isSpecificTestSpecified() {
@@ -2317,7 +2325,9 @@ private ForkStarter createForkStarter(
23172325
platform,
23182326
resolvedJavaModularityResult);
23192327
String configChecksum = getConfigChecksum();
2320-
StartupReportConfiguration startupReportConfiguration = getStartupReportConfiguration(configChecksum, true);
2328+
StartupReportConfiguration startupReportConfiguration =
2329+
getStartupReportConfiguration(configChecksum, true, provider);
2330+
23212331
ProviderConfiguration providerConfiguration = createProviderConfiguration(runOrderParameters);
23222332
return new ForkStarter(
23232333
providerConfiguration,
@@ -2345,7 +2355,8 @@ private InPluginVMSurefireStarter createInprocessStarter(
23452355
platform,
23462356
new ResolvePathResultWrapper(null, true));
23472357
String configChecksum = getConfigChecksum();
2348-
StartupReportConfiguration startupReportConfiguration = getStartupReportConfiguration(configChecksum, false);
2358+
StartupReportConfiguration startupReportConfiguration =
2359+
getStartupReportConfiguration(configChecksum, false, provider);
23492360
ProviderConfiguration providerConfiguration = createProviderConfiguration(runOrderParameters);
23502361
return new InPluginVMSurefireStarter(
23512362
startupConfiguration, providerConfiguration, startupReportConfiguration, getConsoleLogger(), platform);

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
3030
import org.apache.maven.plugin.surefire.log.api.ConsoleLoggerDecorator;
3131
import org.apache.maven.plugin.surefire.report.DefaultReporterFactory;
32+
import org.apache.maven.surefire.api.report.ReporterFactoryOptions;
3233
import org.apache.maven.surefire.api.util.SurefireReflectionException;
3334

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

4951
public CommonReflector(@Nonnull ClassLoader surefireClassLoader) {
@@ -56,6 +58,7 @@ public CommonReflector(@Nonnull ClassLoader surefireClassLoader) {
5658
consoleOutputReporter = surefireClassLoader.loadClass(SurefireConsoleOutputReporter.class.getName());
5759
statelessTestsetInfoReporter =
5860
surefireClassLoader.loadClass(SurefireStatelessTestsetInfoReporter.class.getName());
61+
reporterFactoryOptions = surefireClassLoader.loadClass(ReporterFactoryOptions.class.getName());
5962
} catch (ClassNotFoundException e) {
6063
throw new SurefireReflectionException(e);
6164
}
@@ -90,7 +93,8 @@ private Object createStartupReportConfiguration(@Nonnull StartupReportConfigurat
9093
boolean.class,
9194
statelessTestsetReporter,
9295
consoleOutputReporter,
93-
statelessTestsetInfoReporter);
96+
statelessTestsetInfoReporter,
97+
reporterFactoryOptions);
9498
Object[] params = {
9599
reporterConfiguration.isUseFile(),
96100
reporterConfiguration.isPrintSummary(),
@@ -109,7 +113,8 @@ private Object createStartupReportConfiguration(@Nonnull StartupReportConfigurat
109113
reporterConfiguration.isEnablePropertiesElement(),
110114
reporterConfiguration.getXmlReporter().clone(surefireClassLoader),
111115
reporterConfiguration.getConsoleOutputReporter().clone(surefireClassLoader),
112-
reporterConfiguration.getTestsetReporter().clone(surefireClassLoader)
116+
reporterConfiguration.getTestsetReporter().clone(surefireClassLoader),
117+
reporterConfiguration.getReporterFactoryOptions().clone(surefireClassLoader)
113118
};
114119
return newInstance(constructor, params);
115120
}

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.maven.plugin.surefire.report.TestSetStats;
3636
import org.apache.maven.plugin.surefire.report.WrappedReportEntry;
3737
import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
38+
import org.apache.maven.surefire.api.report.ReporterFactoryOptions;
3839
import org.apache.maven.surefire.extensions.ConsoleOutputReportEventListener;
3940
import org.apache.maven.surefire.extensions.StatelessReportEventListener;
4041
import org.apache.maven.surefire.extensions.StatelessTestsetInfoConsoleReportEventListener;
@@ -97,6 +98,8 @@ public final class StartupReportConfiguration {
9798

9899
private StatisticsReporter statisticsReporter;
99100

101+
private final ReporterFactoryOptions reporterFactoryOptions;
102+
100103
/**
101104
* @since 3.3.1
102105
*/
@@ -119,7 +122,8 @@ public StartupReportConfiguration(
119122
boolean enablePropertiesElement,
120123
SurefireStatelessReporter xmlReporter,
121124
SurefireConsoleOutputReporter consoleOutputReporter,
122-
SurefireStatelessTestsetInfoReporter testsetReporter) {
125+
SurefireStatelessTestsetInfoReporter testsetReporter,
126+
ReporterFactoryOptions reporterFactoryOptions) {
123127
this.useFile = useFile;
124128
this.printSummary = printSummary;
125129
this.reportFormat = reportFormat;
@@ -141,6 +145,7 @@ public StartupReportConfiguration(
141145
this.xmlReporter = xmlReporter;
142146
this.consoleOutputReporter = consoleOutputReporter;
143147
this.testsetReporter = testsetReporter;
148+
this.reporterFactoryOptions = reporterFactoryOptions;
144149
}
145150

146151
@SuppressWarnings("checkstyle:parameternumber")
@@ -180,7 +185,8 @@ public StartupReportConfiguration(
180185
true,
181186
xmlReporter,
182187
consoleOutputReporter,
183-
testsetReporter);
188+
testsetReporter,
189+
new ReporterFactoryOptions(false));
184190
}
185191

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

225231
DefaultStatelessReportMojoConfiguration xmlReporterConfig = new DefaultStatelessReportMojoConfiguration(
226232
resolveReportsDirectory(forkNumber),
@@ -319,4 +325,8 @@ public SurefireStatelessTestsetInfoReporter getTestsetReporter() {
319325
private boolean shouldReportToConsole() {
320326
return isUseFile() ? isPrintSummary() : isRedirectTestOutputToFile() || isBriefOrPlainFormat();
321327
}
328+
329+
public ReporterFactoryOptions getReporterFactoryOptions() {
330+
return reporterFactoryOptions;
331+
}
322332
}

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public TestReportListener<TestOutputReportEntry> createTestReportListener() {
103103
reportConfiguration.isTrimStackTrace(),
104104
PLAIN.equals(reportConfiguration.getReportFormat()),
105105
reportConfiguration.isBriefOrPlainFormat(),
106-
consoleLogger);
106+
consoleLogger,
107+
reportConfiguration.getReporterFactoryOptions().isStatPerSourceName());
107108
addListener(testSetRunListener);
108109
return testSetRunListener;
109110
}

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
import java.io.BufferedOutputStream;
2222
import java.io.File;
23-
import java.io.FileOutputStream;
2423
import java.io.FilterOutputStream;
2524
import java.io.IOException;
2625
import java.io.OutputStream;
2726
import java.io.OutputStreamWriter;
2827
import java.io.PrintWriter;
28+
import java.nio.file.Files;
2929
import java.util.ArrayList;
3030
import java.util.Deque;
3131
import java.util.LinkedHashMap;
@@ -392,7 +392,7 @@ private OutputStream getOutputStream(WrappedReportEntry testSetReportEntry) thro
392392
reportFile.delete();
393393
//noinspection ResultOfMethodCallIgnored
394394
reportDir.mkdirs();
395-
return new BufferedOutputStream(new FileOutputStream(reportFile), 64 * 1024);
395+
return new BufferedOutputStream(Files.newOutputStream(reportFile.toPath()), 64 * 1024);
396396
}
397397

398398
private static OutputStreamWriter getWriter(OutputStream fos) {

0 commit comments

Comments
 (0)