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 16cabe5cf Ensure that the statistics filename is calculated only once.
(#3326)
16cabe5cf is described below
commit 16cabe5cfe82e1789303f4873ca0227fb9abfed3
Author: Alexey Venderov <[email protected]>
AuthorDate: Thu Mar 19 08:17:35 2026 +0100
Ensure that the statistics filename is calculated only once. (#3326)
The issue is that `getStatisticsFile()` uses `getConfigChecksum()` which
relies on potentially mutable values such as system properties, provider
properties, etc. `getStatisticsFile()` was called from different places with
changes to the system properties in between, leading to different filenames.
---
.../plugin/surefire/AbstractSurefireMojo.java | 11 ++++++----
.../maven/plugin/surefire/MojoMocklessTest.java | 25 ++++++++++++++++++----
.../surefire/api/testset/RunOrderParameters.java | 5 -----
.../surefire/api/util/RunOrderCalculatorTest.java | 4 +++-
4 files changed, 31 insertions(+), 14 deletions(-)
diff --git
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
index 82094827f..4cb575ae5 100644
---
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
+++
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
@@ -2099,7 +2099,8 @@ private Artifact getShadefireArtifact() {
return
getPluginArtifactMap().get("org.apache.maven.surefire:surefire-shadefire");
}
- private StartupReportConfiguration getStartupReportConfiguration(boolean
isForking, ProviderInfo providerInfo) {
+ private StartupReportConfiguration getStartupReportConfiguration(
+ boolean isForking, ProviderInfo providerInfo, RunOrderParameters
runOrderParameters) {
SurefireStatelessReporter xmlReporter =
statelessTestsetReporter == null ? new
SurefireStatelessReporter() : statelessTestsetReporter;
@@ -2127,7 +2128,7 @@ private StartupReportConfiguration
getStartupReportConfiguration(boolean isForki
getReportsDirectory(),
isTrimStackTrace(),
getReportNameSuffix(),
- getStatisticsFile(),
+ runOrderParameters.getRunStatisticsFile(),
requiresRunHistory(),
getRerunFailingTestsCount(),
getReportSchemaLocation(),
@@ -2360,7 +2361,8 @@ private ForkStarter createForkStarter(
testClasspathWrapper,
platform,
resolvedJavaModularityResult);
- StartupReportConfiguration startupReportConfiguration =
getStartupReportConfiguration(true, provider);
+ StartupReportConfiguration startupReportConfiguration =
+ getStartupReportConfiguration(true, provider,
runOrderParameters);
ProviderConfiguration providerConfiguration =
createProviderConfiguration(runOrderParameters);
return new ForkStarter(
@@ -2388,7 +2390,8 @@ private InPluginVMSurefireStarter createInprocessStarter(
testClasspathWrapper,
platform,
new ResolvePathResultWrapper(null, true));
- StartupReportConfiguration startupReportConfiguration =
getStartupReportConfiguration(false, provider);
+ StartupReportConfiguration startupReportConfiguration =
+ getStartupReportConfiguration(false, provider,
runOrderParameters);
ProviderConfiguration providerConfiguration =
createProviderConfiguration(runOrderParameters);
return new InPluginVMSurefireStarter(
startupConfiguration, providerConfiguration,
startupReportConfiguration, getConsoleLogger(), platform);
diff --git
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
index 8e2b2326e..9cc1c6296 100644
---
a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
+++
b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
@@ -36,7 +36,9 @@
import org.apache.maven.plugin.surefire.extensions.SurefireStatelessReporter;
import
org.apache.maven.plugin.surefire.extensions.SurefireStatelessTestsetInfoReporter;
import org.apache.maven.surefire.api.suite.RunResult;
+import org.apache.maven.surefire.api.testset.RunOrderParameters;
import org.apache.maven.surefire.api.util.DefaultScanResult;
+import org.apache.maven.surefire.api.util.RunOrder;
import org.apache.maven.surefire.api.util.SureFireFileManager;
import org.apache.maven.surefire.extensions.ForkNodeFactory;
import org.apache.maven.surefire.providerapi.ProviderInfo;
@@ -96,11 +98,24 @@ private static void setInternalState(Object target, String
fieldName, Object val
}
}
+ @Test
+ public void
testGetStartupReportConfigurationUsesProvidedRunStatisticsFile() throws
Exception {
+ AbstractSurefireMojo surefirePlugin = new Mojo(null, null);
+ File runStatisticsFile =
SureFireFileManager.createTempFile(".surefire-", "checksum");
+ RunOrderParameters runOrderParameters = new
RunOrderParameters(RunOrder.DEFAULT, runStatisticsFile);
+ StartupReportConfiguration config = invokeMethod(
+ surefirePlugin, "getStartupReportConfiguration", false,
mock(ProviderInfo.class), runOrderParameters);
+
+ assertThat(config.getStatisticsFile()).isSameAs(runStatisticsFile);
+ }
+
@Test
public void testGetStartupReportConfiguration() throws Exception {
AbstractSurefireMojo surefirePlugin = new Mojo(null, null);
- StartupReportConfiguration config =
- invokeMethod(surefirePlugin, "getStartupReportConfiguration",
false, mock(ProviderInfo.class));
+ RunOrderParameters runOrderParameters =
+ new RunOrderParameters(RunOrder.DEFAULT,
SureFireFileManager.createTempFile(".surefire-", "checksum"));
+ StartupReportConfiguration config = invokeMethod(
+ surefirePlugin, "getStartupReportConfiguration", false,
mock(ProviderInfo.class), runOrderParameters);
assertThat(config.getXmlReporter()).isNotNull().isInstanceOf(SurefireStatelessReporter.class);
@@ -112,6 +127,8 @@ public void testGetStartupReportConfiguration() throws
Exception {
@Test
public void testGetStartupReportConfiguration2() throws Exception {
AbstractSurefireMojo surefirePlugin = new Mojo(null, null);
+ RunOrderParameters runOrderParameters =
+ new RunOrderParameters(RunOrder.DEFAULT,
SureFireFileManager.createTempFile(".surefire-", "checksum"));
SurefireStatelessReporter xmlReporter = new
SurefireStatelessReporter();
SurefireConsoleOutputReporter consoleReporter = new
SurefireConsoleOutputReporter();
SurefireStatelessTestsetInfoReporter testsetInfoReporter = new
SurefireStatelessTestsetInfoReporter();
@@ -119,8 +136,8 @@ public void testGetStartupReportConfiguration2() throws
Exception {
setInternalState(surefirePlugin, "consoleOutputReporter",
consoleReporter);
setInternalState(surefirePlugin, "statelessTestsetInfoReporter",
testsetInfoReporter);
- StartupReportConfiguration config =
- invokeMethod(surefirePlugin, "getStartupReportConfiguration",
false, mock(ProviderInfo.class));
+ StartupReportConfiguration config = invokeMethod(
+ surefirePlugin, "getStartupReportConfiguration", false,
mock(ProviderInfo.class), runOrderParameters);
assertThat(config.getXmlReporter()).isNotNull().isSameAs(xmlReporter);
diff --git
a/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/RunOrderParameters.java
b/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/RunOrderParameters.java
index f07cffc8d..f5256e4fc 100644
---
a/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/RunOrderParameters.java
+++
b/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/RunOrderParameters.java
@@ -22,7 +22,6 @@
import org.apache.maven.surefire.api.util.RunOrder;
-import static org.apache.maven.surefire.api.util.RunOrder.ALPHABETICAL;
import static org.apache.maven.surefire.api.util.RunOrder.DEFAULT;
/**
@@ -53,10 +52,6 @@ public RunOrderParameters(RunOrder[] runOrder, File
runStatisticsFile, Long runO
this.runOrderRandomSeed = runOrderRandomSeed;
}
- public static RunOrderParameters alphabetical() {
- return new RunOrderParameters(new RunOrder[] {ALPHABETICAL}, null);
- }
-
public RunOrder[] getRunOrder() {
return runOrder;
}
diff --git
a/surefire-api/src/test/java/org/apache/maven/surefire/api/util/RunOrderCalculatorTest.java
b/surefire-api/src/test/java/org/apache/maven/surefire/api/util/RunOrderCalculatorTest.java
index 7a26a0829..c4caf6a35 100644
---
a/surefire-api/src/test/java/org/apache/maven/surefire/api/util/RunOrderCalculatorTest.java
+++
b/surefire-api/src/test/java/org/apache/maven/surefire/api/util/RunOrderCalculatorTest.java
@@ -24,6 +24,7 @@
import org.apache.maven.surefire.api.testset.RunOrderParameters;
import org.junit.jupiter.api.Test;
+import static org.apache.maven.surefire.api.util.RunOrder.ALPHABETICAL;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
@@ -35,7 +36,8 @@ public class RunOrderCalculatorTest {
public void testOrderTestClasses() {
getClassesToRun();
TestsToRun testsToRun = new TestsToRun(getClassesToRun());
- RunOrderCalculator runOrderCalculator = new
DefaultRunOrderCalculator(RunOrderParameters.alphabetical(), 1);
+ RunOrderParameters alphabetical = new RunOrderParameters(new
RunOrder[] {ALPHABETICAL}, null);
+ RunOrderCalculator runOrderCalculator = new
DefaultRunOrderCalculator(alphabetical, 1);
final TestsToRun testsToRun1 =
runOrderCalculator.orderTestClasses(testsToRun);
assertEquals(A.class, testsToRun1.iterator().next());
}