Prevent NPE on missing TEST_LOG due to cancel
Tests added that exhibit this failure reported in #11468 without the
correction.
Closes #11494.
PiperOrigin-RevId: 314687670
diff --git a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
index 4881a46..75d7e41 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.exec;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -244,11 +245,17 @@
Path renamedTestLog = null;
for (Pair<String, Path> pair : testOutputs) {
if (TestFileNameConstants.TEST_LOG.equals(pair.getFirst())) {
+ Preconditions.checkState(renamedTestLog == null, "multiple test_log matches");
renamedTestLog = pair.getSecond();
}
}
TestResultData.Builder dataBuilder = result.testResultDataBuilder();
+ // If the test log path does not exist, mark the test as incomplete
+ if (renamedTestLog == null) {
+ dataBuilder.setStatus(BlazeTestStatus.INCOMPLETE);
+ }
+
if (dataBuilder.getStatus() == BlazeTestStatus.PASSED) {
dataBuilder.setPassedLog(renamedTestLog.toString());
} else if (dataBuilder.getStatus() == BlazeTestStatus.INCOMPLETE) {
@@ -400,12 +407,17 @@
return new TestResult(action, data, /*cached*/ true, execRoot);
}
- private static final class StandaloneFailedAttemptResult implements FailedAttemptResult {
+ @VisibleForTesting
+ static final class StandaloneFailedAttemptResult implements FailedAttemptResult {
private final TestResultData testResultData;
StandaloneFailedAttemptResult(TestResultData testResultData) {
this.testResultData = testResultData;
}
+
+ TestResultData testResultData() {
+ return testResultData;
+ }
}
private final class StandaloneTestRunnerSpawn implements TestRunnerSpawn {