gnodet-bot commented on code in PR #14119:
URL: https://github.com/apache/maven/pull/14119#discussion_r4697561223
##########
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:
💡 **Nit (low):** `assertNotEquals(EXECUTED, installStatus)` passes as long
as `install` didn't execute — which includes the case where it remained
`CREATED` (never processed). Since the fix ensures it ends up `SKIPPED`, a
tighter assertion would be more self-documenting and would catch a regression
where the step is stuck in `CREATED` rather than properly skipped:
```suggestion
assertEquals(
BuildStep.SKIPPED,
installStatus,
"install must be SKIPPED when a predecessor step (test)
fails");
```
Same consideration applies to the `deploy` assertion below.
--
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]