Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.2.0] Set exit_code unconditionally on TestResult in BEP #25278

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ private static BuildEventStreamProtos.TestResult.ExecutionInfo extractExecutionI
BuildEventStreamProtos.TestResult.ExecutionInfo.Builder executionInfo =
BuildEventStreamProtos.TestResult.ExecutionInfo.newBuilder();

// The return of `SpawnResult#exitCode()` is noted to only be meaningful if the subprocess
// actually executed. In this position, `spawnResult.exitCode()` is always meaningful,
// because the code only runs if `spawnResult.setupSuccess()` is previously verified to
// be `true`.
executionInfo.setExitCode(spawnResult.exitCode());

if (spawnResult.isCacheHit()) {
result.setRemotelyCached(true);
executionInfo.setCachedRemotely(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ public void testRunTestOnce() throws Exception {
assertThat(result.isCached()).isFalse();
assertThat(result.getTestAction()).isSameInstanceAs(testRunnerAction);
assertThat(result.getData().getTestPassed()).isTrue();
assertThat(result.getData().getExitCode()).isEqualTo(0);
assertThat(result.getData().getRemotelyCached()).isFalse();
assertThat(result.getData().getIsRemoteStrategy()).isFalse();
assertThat(result.getData().getRunDurationMillis()).isEqualTo(10);
Expand Down Expand Up @@ -411,6 +412,7 @@ public void testRunFlakyTest() throws Exception {
assertThat(result.getTestAction()).isSameInstanceAs(testRunnerAction);
assertThat(result.getData().getStatus()).isEqualTo(BlazeTestStatus.FLAKY);
assertThat(result.getData().getTestPassed()).isTrue();
assertThat(result.getData().getExitCode()).isEqualTo(0);
assertThat(result.getData().getRemotelyCached()).isFalse();
assertThat(result.getData().getIsRemoteStrategy()).isFalse();
assertThat(result.getData().getRunDurationMillis()).isEqualTo(15L);
Expand All @@ -425,9 +427,11 @@ public void testRunFlakyTest() throws Exception {
assertThat(failedAttempt.getExecutionInfo().getStrategy()).isEqualTo("test");
assertThat(failedAttempt.getExecutionInfo().getHostname()).isEqualTo("");
assertThat(failedAttempt.getStatus()).isEqualTo(TestStatus.FAILED);
assertThat(failedAttempt.getExecutionInfo().getExitCode()).isEqualTo(1);
assertThat(failedAttempt.getExecutionInfo().getCachedRemotely()).isFalse();
TestAttempt okAttempt = attempts.get(1);
assertThat(okAttempt.getStatus()).isEqualTo(TestStatus.PASSED);
assertThat(okAttempt.getExecutionInfo().getExitCode()).isEqualTo(0);
assertThat(okAttempt.getExecutionInfo().getStrategy()).isEqualTo("test");
assertThat(okAttempt.getExecutionInfo().getHostname()).isEqualTo("");
}
Expand Down Expand Up @@ -483,6 +487,7 @@ public void testRunTestRemotely() throws Exception {
assertThat(result.isCached()).isFalse();
assertThat(result.getTestAction()).isSameInstanceAs(testRunnerAction);
assertThat(result.getData().getTestPassed()).isTrue();
assertThat(result.getData().getExitCode()).isEqualTo(0);
assertThat(result.getData().getRemotelyCached()).isFalse();
assertThat(result.getData().getIsRemoteStrategy()).isTrue();
assertThat(result.getData().getRunDurationMillis()).isEqualTo(10);
Expand All @@ -495,6 +500,7 @@ public void testRunTestRemotely() throws Exception {
.map(TestAttempt.class::cast)
.collect(MoreCollectors.onlyElement());
assertThat(attempt.getStatus()).isEqualTo(TestStatus.PASSED);
assertThat(attempt.getExecutionInfo().getExitCode()).isEqualTo(0);
assertThat(attempt.getExecutionInfo().getStrategy()).isEqualTo("remote");
assertThat(attempt.getExecutionInfo().getHostname()).isEqualTo("a-remote-host");
}
Expand Down Expand Up @@ -551,6 +557,7 @@ public void testRunRemotelyCachedTest() throws Exception {
assertThat(result.isCached()).isFalse();
assertThat(result.getTestAction()).isSameInstanceAs(testRunnerAction);
assertThat(result.getData().getTestPassed()).isTrue();
assertThat(result.getData().getExitCode()).isEqualTo(0);
assertThat(result.getData().getRemotelyCached()).isTrue();
assertThat(result.getData().getIsRemoteStrategy()).isFalse();
assertThat(result.getData().getRunDurationMillis()).isEqualTo(10);
Expand Down Expand Up @@ -911,6 +918,7 @@ public void testExperimentalCancelConcurrentTests() throws Exception {
assertThat(standaloneTestStrategy.postedResult).isNotNull();
assertThat(standaloneTestStrategy.postedResult.getData().getStatus())
.isEqualTo(BlazeTestStatus.PASSED);
assertThat(standaloneTestStrategy.postedResult.getData().getExitCode()).isEqualTo(0);
assertThat(storedEvents.getEvents())
.contains(Event.of(EventKind.PASS, null, "//standalone:empty_test (run 1 of 2)"));
// Reset postedResult.
Expand Down Expand Up @@ -1010,6 +1018,7 @@ public void testExperimentalCancelConcurrentTestsDoesNotTriggerOnFailedRun() thr
assertThat(standaloneTestStrategy.postedResult).isNotNull();
assertThat(standaloneTestStrategy.postedResult.getData().getStatus())
.isEqualTo(BlazeTestStatus.FAILED);
assertThat(standaloneTestStrategy.postedResult.getData().getExitCode()).isEqualTo(1);
assertContainsPrefixedEvent(
storedEvents.getEvents(),
Event.of(EventKind.FAIL, null, "//standalone:empty_test (run 1 of 2)"));
Expand All @@ -1030,6 +1039,7 @@ public void testExperimentalCancelConcurrentTestsDoesNotTriggerOnFailedRun() thr
assertThat(standaloneTestStrategy.postedResult).isNotNull();
assertThat(standaloneTestStrategy.postedResult.getData().getStatus())
.isEqualTo(BlazeTestStatus.PASSED);
assertThat(standaloneTestStrategy.postedResult.getData().getExitCode()).isEqualTo(0);
assertThat(storedEvents.getEvents())
.contains(Event.of(EventKind.PASS, null, "//standalone:empty_test (run 2 of 2)"));
}
Expand Down Expand Up @@ -1116,6 +1126,7 @@ public void testExperimentalCancelConcurrentTestsAllFailed() throws Exception {
assertThat(standaloneTestStrategy.postedResult).isNotNull();
assertThat(standaloneTestStrategy.postedResult.getData().getStatus())
.isEqualTo(BlazeTestStatus.FAILED);
assertThat(standaloneTestStrategy.postedResult.getData().getExitCode()).isEqualTo(1);
assertContainsPrefixedEvent(
storedEvents.getEvents(),
Event.of(EventKind.FAIL, null, "//standalone:empty_test (run 1 of 2)"));
Expand Down Expand Up @@ -1179,5 +1190,6 @@ public void missingTestLogSpawnTestResultIsIncomplete() throws Exception {
assertThat(failedResult).isInstanceOf(StandaloneProcessedAttemptResult.class);
TestResultData data = ((StandaloneProcessedAttemptResult) failedResult).testResultData();
assertThat(data.getStatus()).isEqualTo(BlazeTestStatus.INCOMPLETE);
assertThat(data.getExitCode()).isEqualTo(0);
}
}
Loading