gnodet commented on code in PR #14119:
URL: https://github.com/apache/maven/pull/14119#discussion_r4697852051


##########
impl/maven-core/src/test/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutorTest.java:
##########
@@ -363,6 +364,69 @@ void errorIsStillFatalWhenASecondFailureJoinsIt() throws 
Exception {
                         + session.getResult().getExceptions());
     }
 
+    /**
+     * When a build step (e.g. {@code test}) fails, the matching {@code 
after:test} step is run for
+     * cleanup and ends up with status {@code SKIPPED}. Steps that come after 
it in the lifecycle
+     * (e.g. {@code after:unit-test}, {@code after:verify}, {@code install}, 
{@code deploy}) must
+     * also be skipped: they must not run as if the build had succeeded.
+     *
+     * <p>This is the scenario reported in
+     * <a href="https://github.com/apache/maven/issues/14114";>#14114</a>: with 
the concurrent builder,
+     * {@code install} and {@code deploy} ran even when {@code test} failed, 
because the {@code after:*}
+     * cleanup chain converted a {@code FAILED} predecessor into a {@code 
SKIPPED} predecessor, and the
+     * subsequent {@code shouldExecute} check only guarded against {@code 
FAILED}, not {@code SKIPPED}.
+     */
+    @Test
+    void afterStepSkippedStatusPropagatesAcrossNestedPhases() throws Exception 
{
+        MavenProject project = newProject();
+        MavenSession session = newSession(project);
+
+        ReactorContext reactorContext = newReactorContext(session);
+        try (BuildPlanExecutor.BuildContext context = 
newExecutor((BeforeProjectExecution) event -> {})
+        .new BuildContext(session, reactorContext, 
List.of(newTaskSegment("deploy")))) {
+
+            BuildStep testStep = context.plan
+                    .step(project, "test")
+                    .orElseThrow(() -> new IllegalStateException("no test step 
in the deploy plan"));
+            testStep.exception = new LifecycleExecutionException("test 
failure");
+            testStep.status.set(BuildStep.FAILED);
+
+            context.execute();
+
+            // after:test ran for cleanup and must be SKIPPED (not EXECUTED)
+            int afterTestStatus = context.plan
+                    .step(project, Lifecycle.AFTER + "test")
+                    .map(s -> s.status.get())
+                    .orElse(-1);
+            assertEquals(
+                    BuildStep.SKIPPED, afterTestStatus, "after:test must be 
SKIPPED (ran for cleanup) when test fails");
+
+            // install must NOT have executed
+            int installStatus = context.plan
+                    .step(project, "install")
+                    .map(s -> s.status.get())
+                    .orElse(-1);
+            assertNotEquals(
+                    BuildStep.EXECUTED,
+                    installStatus,
+                    "install must not execute when a predecessor step (test) 
has failed");

Review Comment:
   Investigated, but the tighter assertion does not hold: when `test` FAILED 
and `after:test` ends up SKIPPED, `install`'s direct predecessor `package` (and 
its after-steps) were never processed — they remain in `CREATED` state. Since 
`executePlan()` only visits steps whose predecessors are all `isDone()`, 
`install` itself is never reached and stays `CREATED` (status 0), not `SKIPPED` 
(status 5). The `assertEquals(SKIPPED, ...)` would therefore fail. The original 
`assertNotEquals(EXECUTED, ...)` correctly captures the guarantee: install did 
not run. No change made.



-- 
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