Skip to content

Commit 2774273

Browse files
olamyc00ler
andauthored
Ensure that the statistics filename is calculated only once. (#3326) (#3327)
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. Co-authored-by: Alexey Venderov <[email protected]>
1 parent 0d5df8a commit 2774273

4 files changed

Lines changed: 32 additions & 14 deletions

File tree

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,7 +2081,8 @@ private Artifact getShadefireArtifact() {
20812081
return getPluginArtifactMap().get("org.apache.maven.surefire:surefire-shadefire");
20822082
}
20832083

2084-
private StartupReportConfiguration getStartupReportConfiguration(boolean isForking, ProviderInfo providerInfo) {
2084+
private StartupReportConfiguration getStartupReportConfiguration(
2085+
boolean isForking, ProviderInfo providerInfo, RunOrderParameters runOrderParameters) {
20852086
SurefireStatelessReporter xmlReporter =
20862087
statelessTestsetReporter == null ? new SurefireStatelessReporter() : statelessTestsetReporter;
20872088

@@ -2109,7 +2110,7 @@ private StartupReportConfiguration getStartupReportConfiguration(boolean isForki
21092110
getReportsDirectory(),
21102111
isTrimStackTrace(),
21112112
getReportNameSuffix(),
2112-
getStatisticsFile(),
2113+
runOrderParameters.getRunStatisticsFile(),
21132114
requiresRunHistory(),
21142115
getRerunFailingTestsCount(),
21152116
getReportSchemaLocation(),
@@ -2350,7 +2351,8 @@ private ForkStarter createForkStarter(
23502351
testClasspathWrapper,
23512352
platform,
23522353
resolvedJavaModularityResult);
2353-
StartupReportConfiguration startupReportConfiguration = getStartupReportConfiguration(true, provider);
2354+
StartupReportConfiguration startupReportConfiguration =
2355+
getStartupReportConfiguration(true, provider, runOrderParameters);
23542356

23552357
ProviderConfiguration providerConfiguration = createProviderConfiguration(runOrderParameters);
23562358
return new ForkStarter(
@@ -2378,7 +2380,8 @@ private InPluginVMSurefireStarter createInprocessStarter(
23782380
testClasspathWrapper,
23792381
platform,
23802382
new ResolvePathResultWrapper(null, true));
2381-
StartupReportConfiguration startupReportConfiguration = getStartupReportConfiguration(false, provider);
2383+
StartupReportConfiguration startupReportConfiguration =
2384+
getStartupReportConfiguration(false, provider, runOrderParameters);
23822385
ProviderConfiguration providerConfiguration = createProviderConfiguration(runOrderParameters);
23832386
return new InPluginVMSurefireStarter(
23842387
startupConfiguration, providerConfiguration, startupReportConfiguration, getConsoleLogger(), platform);

‎maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
import org.apache.maven.plugin.surefire.extensions.SurefireStatelessReporter;
3535
import org.apache.maven.plugin.surefire.extensions.SurefireStatelessTestsetInfoReporter;
3636
import org.apache.maven.surefire.api.suite.RunResult;
37+
import org.apache.maven.surefire.api.testset.RunOrderParameters;
3738
import org.apache.maven.surefire.api.util.DefaultScanResult;
39+
import org.apache.maven.surefire.api.util.RunOrder;
3840
import org.apache.maven.surefire.api.util.SureFireFileManager;
3941
import org.apache.maven.surefire.extensions.ForkNodeFactory;
4042
import org.apache.maven.surefire.providerapi.ProviderInfo;
@@ -53,11 +55,24 @@
5355
*
5456
*/
5557
public class MojoMocklessTest {
58+
@Test
59+
public void testGetStartupReportConfigurationUsesProvidedRunStatisticsFile() throws Exception {
60+
AbstractSurefireMojo surefirePlugin = new Mojo(null, null);
61+
File runStatisticsFile = SureFireFileManager.createTempFile(".surefire-", "checksum");
62+
RunOrderParameters runOrderParameters = new RunOrderParameters(RunOrder.DEFAULT, runStatisticsFile);
63+
StartupReportConfiguration config = invokeMethod(
64+
surefirePlugin, "getStartupReportConfiguration", false, mock(ProviderInfo.class), runOrderParameters);
65+
66+
assertThat(config.getStatisticsFile()).isSameAs(runStatisticsFile);
67+
}
68+
5669
@Test
5770
public void testGetStartupReportConfiguration() throws Exception {
5871
AbstractSurefireMojo surefirePlugin = new Mojo(null, null);
59-
StartupReportConfiguration config =
60-
invokeMethod(surefirePlugin, "getStartupReportConfiguration", false, mock(ProviderInfo.class));
72+
RunOrderParameters runOrderParameters =
73+
new RunOrderParameters(RunOrder.DEFAULT, SureFireFileManager.createTempFile(".surefire-", "checksum"));
74+
StartupReportConfiguration config = invokeMethod(
75+
surefirePlugin, "getStartupReportConfiguration", false, mock(ProviderInfo.class), runOrderParameters);
6176

6277
assertThat(config.getXmlReporter()).isNotNull().isInstanceOf(SurefireStatelessReporter.class);
6378

@@ -69,15 +84,17 @@ public void testGetStartupReportConfiguration() throws Exception {
6984
@Test
7085
public void testGetStartupReportConfiguration2() throws Exception {
7186
AbstractSurefireMojo surefirePlugin = new Mojo(null, null);
87+
RunOrderParameters runOrderParameters =
88+
new RunOrderParameters(RunOrder.DEFAULT, SureFireFileManager.createTempFile(".surefire-", "checksum"));
7289
SurefireStatelessReporter xmlReporter = new SurefireStatelessReporter();
7390
SurefireConsoleOutputReporter consoleReporter = new SurefireConsoleOutputReporter();
7491
SurefireStatelessTestsetInfoReporter testsetInfoReporter = new SurefireStatelessTestsetInfoReporter();
7592
setInternalState(surefirePlugin, "statelessTestsetReporter", xmlReporter);
7693
setInternalState(surefirePlugin, "consoleOutputReporter", consoleReporter);
7794
setInternalState(surefirePlugin, "statelessTestsetInfoReporter", testsetInfoReporter);
7895

79-
StartupReportConfiguration config =
80-
invokeMethod(surefirePlugin, "getStartupReportConfiguration", false, mock(ProviderInfo.class));
96+
StartupReportConfiguration config = invokeMethod(
97+
surefirePlugin, "getStartupReportConfiguration", false, mock(ProviderInfo.class), runOrderParameters);
8198

8299
assertThat(config.getXmlReporter()).isNotNull().isSameAs(xmlReporter);
83100

‎surefire-api/src/main/java/org/apache/maven/surefire/api/testset/RunOrderParameters.java‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import org.apache.maven.surefire.api.util.RunOrder;
2424

25-
import static org.apache.maven.surefire.api.util.RunOrder.ALPHABETICAL;
2625
import static org.apache.maven.surefire.api.util.RunOrder.DEFAULT;
2726

2827
/**
@@ -53,10 +52,6 @@ public RunOrderParameters(RunOrder[] runOrder, File runStatisticsFile, Long runO
5352
this.runOrderRandomSeed = runOrderRandomSeed;
5453
}
5554

56-
public static RunOrderParameters alphabetical() {
57-
return new RunOrderParameters(new RunOrder[] {ALPHABETICAL}, null);
58-
}
59-
6055
public RunOrder[] getRunOrder() {
6156
return runOrder;
6257
}

‎surefire-api/src/test/java/org/apache/maven/surefire/api/util/RunOrderCalculatorTest.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import junit.framework.TestCase;
2525
import org.apache.maven.surefire.api.testset.RunOrderParameters;
2626

27+
import static org.apache.maven.surefire.api.util.RunOrder.ALPHABETICAL;
28+
2729
/**
2830
* @author Kristian Rosenvold
2931
*/
@@ -32,7 +34,8 @@ public class RunOrderCalculatorTest extends TestCase {
3234
public void testOrderTestClasses() {
3335
getClassesToRun();
3436
TestsToRun testsToRun = new TestsToRun(getClassesToRun());
35-
RunOrderCalculator runOrderCalculator = new DefaultRunOrderCalculator(RunOrderParameters.alphabetical(), 1);
37+
RunOrderParameters alphabetical = new RunOrderParameters(new RunOrder[] {ALPHABETICAL}, null);
38+
RunOrderCalculator runOrderCalculator = new DefaultRunOrderCalculator(alphabetical, 1);
3639
final TestsToRun testsToRun1 = runOrderCalculator.orderTestClasses(testsToRun);
3740
assertEquals(A.class, testsToRun1.iterator().next());
3841
}

0 commit comments

Comments
 (0)