This is an automated email from the ASF dual-hosted git repository.
olamy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/master by this push:
new ff6b6e30f Use parallel tests with Junit5 feature (#3316)
ff6b6e30f is described below
commit ff6b6e30f6232fd69686788b6482addc15335b3f
Author: Olivier Lamy <[email protected]>
AuthorDate: Tue Mar 17 19:07:33 2026 +1000
Use parallel tests with Junit5 feature (#3316)
* parallel run with Junit5 feature
---------
Signed-off-by: Olivier Lamy <[email protected]>
---
.mvn/extensions.xml | 4 +-
...BooterDeserializerStartupConfigurationTest.java | 90 +++++++++-------------
pom.xml | 15 +++-
.../maven/surefire/booter/ForkedBooterTest.java | 2 +
surefire-its/pom.xml | 17 ++--
5 files changed, 61 insertions(+), 67 deletions(-)
diff --git a/.mvn/extensions.xml b/.mvn/extensions.xml
index 66d6ddebe..5b611d154 100644
--- a/.mvn/extensions.xml
+++ b/.mvn/extensions.xml
@@ -17,11 +17,11 @@
~ under the License.
-->
<extensions>
- <extension>
+ <!--extension>
<groupId>eu.maveniverse.maven.mimir</groupId>
<artifactId>extension3</artifactId>
<version>0.11.2</version>
- </extension>
+ </extension-->
<!--
cannot use the cache because of shaded artifact surefire-shared-utils
the primary artifact is in the cache but the shaded one is not replacing it
diff --git
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
index bb6385d41..de95ca93e 100644
---
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
+++
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
@@ -19,15 +19,16 @@
package org.apache.maven.plugin.surefire.booterclient;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
-import org.apache.commons.io.FileUtils;
import org.apache.maven.surefire.api.booter.Shutdown;
import org.apache.maven.surefire.api.cli.CommandLineOption;
import org.apache.maven.surefire.api.report.ReporterConfiguration;
@@ -45,9 +46,8 @@
import org.apache.maven.surefire.booter.PropertiesWrapper;
import org.apache.maven.surefire.booter.ProviderConfiguration;
import org.apache.maven.surefire.booter.StartupConfiguration;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import static
org.apache.maven.surefire.api.cli.CommandLineOption.LOGGING_LEVEL_DEBUG;
import static
org.apache.maven.surefire.api.cli.CommandLineOption.REACTOR_FAIL_FAST;
@@ -55,8 +55,8 @@
import static org.apache.maven.surefire.booter.ProcessCheckerType.ALL;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Performs roundtrip testing of serialization/deserialization of The
StartupConfiguration
@@ -65,44 +65,29 @@
*/
public class BooterDeserializerStartupConfigurationTest {
- private static int idx = 0;
-
- private File basedir;
-
private final ClasspathConfiguration classpathConfiguration =
createClasspathConfiguration();
private final List<CommandLineOption> cli =
Arrays.asList(LOGGING_LEVEL_DEBUG, SHOW_ERRORS, REACTOR_FAIL_FAST);
- @BeforeEach
- public void setupDirectories() throws IOException {
- File target = new File(System.getProperty("user.dir"), "target");
- basedir = new File(target,
"BooterDeserializerProviderConfigurationTest-" + ++idx);
- FileUtils.deleteDirectory(basedir);
- assertTrue(basedir.mkdirs());
- }
-
- @AfterEach
- public void deleteDirectories() throws IOException {
- FileUtils.deleteDirectory(basedir);
- }
-
@Test
- public void testProvider() throws IOException {
- assertEquals("com.provider",
getReloadedStartupConfiguration().getProviderClassName());
+ public void testProvider(@TempDir Path tempDir) throws IOException {
+ assertEquals(
+ "com.provider",
+
getReloadedStartupConfiguration(tempDir.toFile()).getProviderClassName());
}
@Test
- public void testClassPathConfiguration() throws IOException {
+ public void testClassPathConfiguration(@TempDir Path tempDir) throws
IOException {
AbstractPathConfiguration reloadedClasspathConfiguration =
- getReloadedStartupConfiguration().getClasspathConfiguration();
+
getReloadedStartupConfiguration(tempDir.toFile()).getClasspathConfiguration();
- assertTrue(reloadedClasspathConfiguration instanceof
ClasspathConfiguration);
+ assertInstanceOf(ClasspathConfiguration.class,
reloadedClasspathConfiguration);
assertCpConfigEquals(classpathConfiguration, (ClasspathConfiguration)
reloadedClasspathConfiguration);
}
@Test
- public void testProcessChecker() throws IOException {
- assertEquals(ALL,
getReloadedStartupConfiguration().getProcessChecker());
+ public void testProcessChecker(@TempDir Path tempDir) throws IOException {
+ assertEquals(ALL,
getReloadedStartupConfiguration(tempDir.toFile()).getProcessChecker());
}
private void assertCpConfigEquals(
@@ -117,32 +102,34 @@ private void assertCpConfigEquals(
}
@Test
- public void testClassLoaderConfiguration() throws IOException {
-
assertFalse(getReloadedStartupConfiguration().isManifestOnlyJarRequestedAndUsable());
+ public void testClassLoaderConfiguration(@TempDir Path tempDir) throws
IOException {
+
assertFalse(getReloadedStartupConfiguration(tempDir.toFile()).isManifestOnlyJarRequestedAndUsable());
}
@Test
- public void testClassLoaderConfigurationTrues() throws IOException {
+ public void testClassLoaderConfigurationTrues(@TempDir Path tempDir)
throws IOException {
final StartupConfiguration testStartupConfiguration =
getTestStartupConfiguration(getManifestOnlyJarForkConfiguration());
boolean current =
testStartupConfiguration.isManifestOnlyJarRequestedAndUsable();
- assertEquals(current,
saveAndReload(testStartupConfiguration).isManifestOnlyJarRequestedAndUsable());
+ assertEquals(
+ current,
+ saveAndReload(testStartupConfiguration,
tempDir.toFile()).isManifestOnlyJarRequestedAndUsable());
}
@Test
- public void testProcessCheckerAll() throws IOException {
- assertEquals(ALL,
getReloadedStartupConfiguration().getProcessChecker());
+ public void testProcessCheckerAll(@TempDir Path tempDir) throws
IOException {
+ assertEquals(ALL,
getReloadedStartupConfiguration(tempDir.toFile()).getProcessChecker());
}
@Test
- public void testProcessCheckerNull() throws IOException {
+ public void testProcessCheckerNull(@TempDir Path tempDir) throws
IOException {
StartupConfiguration startupConfiguration = new StartupConfiguration(
"com.provider",
classpathConfiguration,
getManifestOnlyJarForkConfiguration(),
null,
- Collections.<String[]>emptyList());
- assertNull(saveAndReload(startupConfiguration).getProcessChecker());
+ Collections.emptyList());
+ assertNull(saveAndReload(startupConfiguration,
tempDir.toFile()).getProcessChecker());
}
private ClasspathConfiguration createClasspathConfiguration() {
@@ -159,14 +146,15 @@ private static ClassLoaderConfiguration
getManifestOnlyJarForkConfiguration() {
return new ClassLoaderConfiguration(true, true);
}
- private StartupConfiguration getReloadedStartupConfiguration() throws
IOException {
+ private StartupConfiguration getReloadedStartupConfiguration(File basedir)
throws IOException {
ClassLoaderConfiguration classLoaderConfiguration =
getSystemClassLoaderConfiguration();
- return
saveAndReload(getTestStartupConfiguration(classLoaderConfiguration));
+ return
saveAndReload(getTestStartupConfiguration(classLoaderConfiguration), basedir);
}
- private StartupConfiguration saveAndReload(StartupConfiguration
startupConfiguration) throws IOException {
+ private StartupConfiguration saveAndReload(StartupConfiguration
startupConfiguration, File basedir)
+ throws IOException {
final ForkConfiguration forkConfiguration =
ForkConfigurationTest.getForkConfiguration(basedir, null);
- PropertiesWrapper props = new PropertiesWrapper(new HashMap<String,
String>());
+ PropertiesWrapper props = new PropertiesWrapper(new HashMap<>());
BooterSerializer booterSerializer = new
BooterSerializer(forkConfiguration);
String aTest = "aTest";
File propsTest = booterSerializer.serialize(
@@ -178,10 +166,12 @@ private StartupConfiguration
saveAndReload(StartupConfiguration startupConfigura
null,
1,
"tcp://localhost:63003");
- BooterDeserializer booterDeserializer = new BooterDeserializer(new
FileInputStream(propsTest));
- assertNull(booterDeserializer.getPluginPid());
- assertEquals("tcp://localhost:63003",
booterDeserializer.getConnectionString());
- return booterDeserializer.getStartupConfiguration();
+ try (InputStream inputStream =
Files.newInputStream(propsTest.toPath())) {
+ BooterDeserializer booterDeserializer = new
BooterDeserializer(inputStream);
+ assertNull(booterDeserializer.getPluginPid());
+ assertEquals("tcp://localhost:63003",
booterDeserializer.getConnectionString());
+ return booterDeserializer.getStartupConfiguration();
+ }
}
private ProviderConfiguration getProviderConfiguration() {
@@ -199,7 +189,7 @@ private ProviderConfiguration getProviderConfiguration() {
reporterConfiguration,
new TestArtifactInfo("5.0", "ABC"),
testSuiteDefinition,
- new HashMap<String, String>(),
+ new HashMap<>(),
BooterDeserializerProviderConfigurationTest.TEST_TYPED,
true,
cli,
@@ -210,11 +200,7 @@ private ProviderConfiguration getProviderConfiguration() {
private StartupConfiguration
getTestStartupConfiguration(ClassLoaderConfiguration classLoaderConfiguration) {
return new StartupConfiguration(
- "com.provider",
- classpathConfiguration,
- classLoaderConfiguration,
- ALL,
- Collections.<String[]>emptyList());
+ "com.provider", classpathConfiguration,
classLoaderConfiguration, ALL, Collections.emptyList());
}
private File getTestSourceDirectory() {
diff --git a/pom.xml b/pom.xml
index a0d0a9ee0..c1c8a1741 100644
--- a/pom.xml
+++ b/pom.xml
@@ -87,6 +87,12 @@
<properties>
<javaVersion>8</javaVersion>
+
<junit.jupiter.execution.parallel.config.dynamic.factor>0.8</junit.jupiter.execution.parallel.config.dynamic.factor>
+
<junit.jupiter.execution.parallel.config.fixed.parallelism>2</junit.jupiter.execution.parallel.config.fixed.parallelism>
+
<junit.jupiter.execution.parallel.config.strategy>dynamic</junit.jupiter.execution.parallel.config.strategy>
+
<junit.jupiter.execution.parallel.enabled>true</junit.jupiter.execution.parallel.enabled>
+
<junit.jupiter.execution.parallel.mode.classes.default>concurrent</junit.jupiter.execution.parallel.mode.classes.default>
+
<junit.jupiter.execution.parallel.mode.default>same_thread</junit.jupiter.execution.parallel.mode.default>
<mavenVersion>3.6.3</mavenVersion>
<resolverVersion>1.4.1</resolverVersion>
<commonsLang3Version>3.20.0</commonsLang3Version>
@@ -215,7 +221,6 @@
<version>2.4.2</version>
</dependency>
<dependency>
- <!-- Do not upgrade, needs code changes -->
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-verifier</artifactId>
<version>2.0.0-M1</version>
@@ -299,6 +304,14 @@
<version>3.5.5</version>
<!-- ${shadedVersion}, but resolved due to
https://issues.apache.org/jira/browse/MRELEASE-799 -->
<configuration>
+ <properties>
+
<configurationParameters>junit.jupiter.execution.parallel.enabled=${junit.jupiter.execution.parallel.enabled}
+
junit.jupiter.execution.parallel.mode.default=${junit.jupiter.execution.parallel.mode.default}
+
junit.jupiter.execution.parallel.mode.classes.default=${junit.jupiter.execution.parallel.mode.classes.default}
+
junit.jupiter.execution.parallel.config.strategy=${junit.jupiter.execution.parallel.config.strategy}
+
junit.jupiter.execution.parallel.config.fixed.parallelism=${junit.jupiter.execution.parallel.config.fixed.parallelism}
+
junit.jupiter.execution.parallel.config.dynamic.factor=${junit.jupiter.execution.parallel.config.dynamic.factor}</configurationParameters>
+ </properties>
<!-- NOTE: Be sure to isolate the Surefire version under test from
the version running the tests! -->
<useSystemClassLoader>false</useSystemClassLoader>
<argLine>${jvm.args.tests}</argLine>
diff --git
a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterTest.java
b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterTest.java
index 3997ad5f6..ec28d9ce6 100644
---
a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterTest.java
+++
b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterTest.java
@@ -36,6 +36,7 @@
import org.apache.maven.surefire.api.util.SureFireFileManager;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.parallel.Isolated;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
@@ -45,6 +46,7 @@
* Tests for {@link ForkedBooter}.
*/
@SuppressWarnings("checkstyle:magicnumber")
+@Isolated
public class ForkedBooterTest {
private static Object invokeMethod(Class<?> clazz, String methodName,
Object... args) throws Exception {
diff --git a/surefire-its/pom.xml b/surefire-its/pom.xml
index 5799470bf..0ab109663 100644
--- a/surefire-its/pom.xml
+++ b/surefire-its/pom.xml
@@ -34,16 +34,14 @@
<properties>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<surefire.rerunFailingTestsCount>0</surefire.rerunFailingTestsCount>
- <its.forkCount>0.5C</its.forkCount>
- <its.threadCount>1</its.threadCount>
<maven.deploy.skip>true</maven.deploy.skip>
<maven.install.skip>true</maven.install.skip>
<maven.javadoc.skip>true</maven.javadoc.skip>
-
<junit.vintage.execution.parallel.enabled>false</junit.vintage.execution.parallel.enabled>
-
<junit.vintage.execution.parallel.classes>false</junit.vintage.execution.parallel.classes>
-
<junit.vintage.execution.parallel.methods>false</junit.vintage.execution.parallel.methods>
-
<junit.vintage.execution.parallel.pool>5</junit.vintage.execution.parallel.pool>
<maven.clean.fast>true</maven.clean.fast>
+ <its.forkCount>0.5C</its.forkCount>
+ <its.threadCount>1</its.threadCount>
+ <!-- verifier embeded is definitely not thread safe -->
+
<junit.jupiter.execution.parallel.enabled>false</junit.jupiter.execution.parallel.enabled>
</properties>
<dependencies>
@@ -226,12 +224,6 @@
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
- <properties>
-
<configurationParameters>junit.vintage.execution.parallel.enabled=${junit.vintage.execution.parallel.enabled}
-
junit.vintage.execution.parallel.classes=${junit.vintage.execution.parallel.classes}
-
junit.vintage.execution.parallel.methods=${junit.vintage.execution.parallel.methods}
-
junit.vintage.execution.parallel.pool-size=${junit.vintage.execution.parallel.pool}</configurationParameters>
- </properties>
<skipTests>${skipTests}</skipTests>
<runOrder>alphabetical</runOrder>
<forkCount>${its.forkCount}</forkCount>
@@ -297,6 +289,7 @@
</property>
</activation>
<properties>
+ <surefire.rerunFailingTestsCount>1</surefire.rerunFailingTestsCount>
<!-- workaround for SUREFIRE-2269 -->
<maven.clean.failOnError>false</maven.clean.failOnError>
<maven.clean.verbose>true</maven.clean.verbose>