Skip to content

Commit d5d9385

Browse files
aaronskycopybara-github
authored andcommitted
Set exit_code unconditionally on TestResult in BEP
Fixes #25165 I hope I did this right. I am able to see the output in my repro on rules_apple (which I can share if required by code review). Let me know if there's anything I've overlooked! It would be great to get this into 8.1.0 if possible. Closes #25203. PiperOrigin-RevId: 725718124 Change-Id: I9c845ce1dc18307f5932da972f4ad31058a42f89
1 parent c8e5119 commit d5d9385

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java

+6
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,12 @@ private static BuildEventStreamProtos.TestResult.ExecutionInfo extractExecutionI
367367
BuildEventStreamProtos.TestResult.ExecutionInfo.Builder executionInfo =
368368
BuildEventStreamProtos.TestResult.ExecutionInfo.newBuilder();
369369

370+
// The return of `SpawnResult#exitCode()` is noted to only be meaningful if the subprocess
371+
// actually executed. In this position, `spawnResult.exitCode()` is always meaningful,
372+
// because the code only runs if `spawnResult.setupSuccess()` is previously verified to
373+
// be `true`.
374+
executionInfo.setExitCode(spawnResult.exitCode());
375+
370376
if (spawnResult.isCacheHit()) {
371377
result.setRemotelyCached(true);
372378
executionInfo.setCachedRemotely(true);

src/test/java/com/google/devtools/build/lib/exec/StandaloneTestStrategyTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ public void testRunTestOnce() throws Exception {
331331
assertThat(result.isCached()).isFalse();
332332
assertThat(result.getTestAction()).isSameInstanceAs(testRunnerAction);
333333
assertThat(result.getData().getTestPassed()).isTrue();
334+
assertThat(result.getData().getExitCode()).isEqualTo(0);
334335
assertThat(result.getData().getRemotelyCached()).isFalse();
335336
assertThat(result.getData().getIsRemoteStrategy()).isFalse();
336337
assertThat(result.getData().getRunDurationMillis()).isEqualTo(10);
@@ -411,6 +412,7 @@ public void testRunFlakyTest() throws Exception {
411412
assertThat(result.getTestAction()).isSameInstanceAs(testRunnerAction);
412413
assertThat(result.getData().getStatus()).isEqualTo(BlazeTestStatus.FLAKY);
413414
assertThat(result.getData().getTestPassed()).isTrue();
415+
assertThat(result.getData().getExitCode()).isEqualTo(0);
414416
assertThat(result.getData().getRemotelyCached()).isFalse();
415417
assertThat(result.getData().getIsRemoteStrategy()).isFalse();
416418
assertThat(result.getData().getRunDurationMillis()).isEqualTo(15L);
@@ -425,9 +427,11 @@ public void testRunFlakyTest() throws Exception {
425427
assertThat(failedAttempt.getExecutionInfo().getStrategy()).isEqualTo("test");
426428
assertThat(failedAttempt.getExecutionInfo().getHostname()).isEqualTo("");
427429
assertThat(failedAttempt.getStatus()).isEqualTo(TestStatus.FAILED);
430+
assertThat(failedAttempt.getExecutionInfo().getExitCode()).isEqualTo(1);
428431
assertThat(failedAttempt.getExecutionInfo().getCachedRemotely()).isFalse();
429432
TestAttempt okAttempt = attempts.get(1);
430433
assertThat(okAttempt.getStatus()).isEqualTo(TestStatus.PASSED);
434+
assertThat(okAttempt.getExecutionInfo().getExitCode()).isEqualTo(0);
431435
assertThat(okAttempt.getExecutionInfo().getStrategy()).isEqualTo("test");
432436
assertThat(okAttempt.getExecutionInfo().getHostname()).isEqualTo("");
433437
}
@@ -483,6 +487,7 @@ public void testRunTestRemotely() throws Exception {
483487
assertThat(result.isCached()).isFalse();
484488
assertThat(result.getTestAction()).isSameInstanceAs(testRunnerAction);
485489
assertThat(result.getData().getTestPassed()).isTrue();
490+
assertThat(result.getData().getExitCode()).isEqualTo(0);
486491
assertThat(result.getData().getRemotelyCached()).isFalse();
487492
assertThat(result.getData().getIsRemoteStrategy()).isTrue();
488493
assertThat(result.getData().getRunDurationMillis()).isEqualTo(10);
@@ -495,6 +500,7 @@ public void testRunTestRemotely() throws Exception {
495500
.map(TestAttempt.class::cast)
496501
.collect(MoreCollectors.onlyElement());
497502
assertThat(attempt.getStatus()).isEqualTo(TestStatus.PASSED);
503+
assertThat(attempt.getExecutionInfo().getExitCode()).isEqualTo(0);
498504
assertThat(attempt.getExecutionInfo().getStrategy()).isEqualTo("remote");
499505
assertThat(attempt.getExecutionInfo().getHostname()).isEqualTo("a-remote-host");
500506
}
@@ -551,6 +557,7 @@ public void testRunRemotelyCachedTest() throws Exception {
551557
assertThat(result.isCached()).isFalse();
552558
assertThat(result.getTestAction()).isSameInstanceAs(testRunnerAction);
553559
assertThat(result.getData().getTestPassed()).isTrue();
560+
assertThat(result.getData().getExitCode()).isEqualTo(0);
554561
assertThat(result.getData().getRemotelyCached()).isTrue();
555562
assertThat(result.getData().getIsRemoteStrategy()).isFalse();
556563
assertThat(result.getData().getRunDurationMillis()).isEqualTo(10);
@@ -911,6 +918,7 @@ public void testExperimentalCancelConcurrentTests() throws Exception {
911918
assertThat(standaloneTestStrategy.postedResult).isNotNull();
912919
assertThat(standaloneTestStrategy.postedResult.getData().getStatus())
913920
.isEqualTo(BlazeTestStatus.PASSED);
921+
assertThat(standaloneTestStrategy.postedResult.getData().getExitCode()).isEqualTo(0);
914922
assertThat(storedEvents.getEvents())
915923
.contains(Event.of(EventKind.PASS, null, "//standalone:empty_test (run 1 of 2)"));
916924
// Reset postedResult.
@@ -1010,6 +1018,7 @@ public void testExperimentalCancelConcurrentTestsDoesNotTriggerOnFailedRun() thr
10101018
assertThat(standaloneTestStrategy.postedResult).isNotNull();
10111019
assertThat(standaloneTestStrategy.postedResult.getData().getStatus())
10121020
.isEqualTo(BlazeTestStatus.FAILED);
1021+
assertThat(standaloneTestStrategy.postedResult.getData().getExitCode()).isEqualTo(1);
10131022
assertContainsPrefixedEvent(
10141023
storedEvents.getEvents(),
10151024
Event.of(EventKind.FAIL, null, "//standalone:empty_test (run 1 of 2)"));
@@ -1030,6 +1039,7 @@ public void testExperimentalCancelConcurrentTestsDoesNotTriggerOnFailedRun() thr
10301039
assertThat(standaloneTestStrategy.postedResult).isNotNull();
10311040
assertThat(standaloneTestStrategy.postedResult.getData().getStatus())
10321041
.isEqualTo(BlazeTestStatus.PASSED);
1042+
assertThat(standaloneTestStrategy.postedResult.getData().getExitCode()).isEqualTo(0);
10331043
assertThat(storedEvents.getEvents())
10341044
.contains(Event.of(EventKind.PASS, null, "//standalone:empty_test (run 2 of 2)"));
10351045
}
@@ -1116,6 +1126,7 @@ public void testExperimentalCancelConcurrentTestsAllFailed() throws Exception {
11161126
assertThat(standaloneTestStrategy.postedResult).isNotNull();
11171127
assertThat(standaloneTestStrategy.postedResult.getData().getStatus())
11181128
.isEqualTo(BlazeTestStatus.FAILED);
1129+
assertThat(standaloneTestStrategy.postedResult.getData().getExitCode()).isEqualTo(1);
11191130
assertContainsPrefixedEvent(
11201131
storedEvents.getEvents(),
11211132
Event.of(EventKind.FAIL, null, "//standalone:empty_test (run 1 of 2)"));
@@ -1179,5 +1190,6 @@ public void missingTestLogSpawnTestResultIsIncomplete() throws Exception {
11791190
assertThat(failedResult).isInstanceOf(StandaloneProcessedAttemptResult.class);
11801191
TestResultData data = ((StandaloneProcessedAttemptResult) failedResult).testResultData();
11811192
assertThat(data.getStatus()).isEqualTo(BlazeTestStatus.INCOMPLETE);
1193+
assertThat(data.getExitCode()).isEqualTo(0);
11821194
}
11831195
}

0 commit comments

Comments
 (0)