olamy commented on code in PR #3646:
URL: https://github.com/apache/maven-surefire/pull/3646#discussion_r4731198441


##########
maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java:
##########
@@ -623,16 +625,29 @@ public void setRunLastFailed(boolean runLastFailed) {
     @SuppressWarnings("unchecked")
     protected void handleSummary(RunResult summary, Exception 
firstForkException)
             throws MojoExecutionException, MojoFailureException {
+        File summaryFile = getSummaryFile();
         try {
+            // Executions sharing a summary file add up their results in it. 
The flag is kept per file: the first
+            // write to a file in this build replaces what the previous build 
left there.
+            String inProgressKey = FAILSAFE_IN_PROGRESS_CONTEXT_KEY + ":" + 
toAbsoluteCanonical(summaryFile);
+            boolean inProgress = getPluginContext().containsKey(inProgressKey);
             if (!summary.isNoTestsRun()) {
-                Object token = 
getPluginContext().get(FAILSAFE_IN_PROGRESS_CONTEXT_KEY);
-                writeSummary(summary, getSummaryFile(), token != null);
+                writeSummary(summary, summaryFile, inProgress);
+            } else if (!inProgress && isFromAnEarlierBuild(summaryFile)) {
+                // nothing ran: drop the previous build's summary, but don't 
create an empty one (SUREFIRE-2124)
+                Files.deleteIfExists(summaryFile.toPath());

Review Comment:
   Sharing one summary file between several modules isn't a supported setup. 
The default is one file per module under `target/failsafe-reports`, and the 
docs and ITs all use one file per execution, merged by `verify` through 
`summaryFiles`.
   
   Master already breaks there, and without any race: the plugin context is per 
project, so each module's first write overwrites the file and drops the other 
module's result. Supporting a shared summary properly would need its own design 
(locking across modules), so I'm keeping this PR as it is.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to