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 e266e7a23676d1..99a2cc3c2442e4 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,8 @@ package com.google.devtools.build.lib.exec; +import static java.nio.charset.StandardCharsets.UTF_8; + import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.base.Verify; @@ -65,7 +67,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -655,25 +656,7 @@ private TestAttemptResult runTestAttempt( try { spawnResults = resolver.exec(spawn, actionExecutionContext.withFileOutErr(fileOutErr)); testResultDataBuilder = TestResultData.newBuilder(); - if (actionExecutionContext - .getPathResolver() - .convertPath(resolvedPaths.getExitSafeFile()) - .exists()) { - testResultDataBuilder - .setCachable(false) - .setTestPassed(false) - .setStatus(BlazeTestStatus.FAILED); - fileOutErr - .getErrorStream() - .write( - "-- Test exited prematurely (TEST_PREMATURE_EXIT_FILE exists) --\n" - .getBytes(StandardCharsets.UTF_8)); - } else { - testResultDataBuilder - .setCachable(true) - .setTestPassed(true) - .setStatus(BlazeTestStatus.PASSED); - } + testResultDataBuilder.setCachable(true).setTestPassed(true).setStatus(BlazeTestStatus.PASSED); } catch (SpawnExecException e) { if (e.isCatastrophic()) { closeSuppressed(e, streamed); @@ -699,6 +682,22 @@ private TestAttemptResult runTestAttempt( } long endTimeMillis = actionExecutionContext.getClock().currentTimeMillis(); + // Check TEST_PREMATURE_EXIT_FILE file (and always delete it) + if (actionExecutionContext + .getPathResolver() + .convertPath(resolvedPaths.getExitSafeFile()) + .delete() + && testResultDataBuilder.getTestPassed()) { + testResultDataBuilder + .setCachable(false) + .setTestPassed(false) + .setStatus(BlazeTestStatus.FAILED); + fileOutErr + .getErrorStream() + .write( + "-- Test exited prematurely (TEST_PREMATURE_EXIT_FILE exists) --\n".getBytes(UTF_8)); + } + // Do not override a more informative test failure with a generic failure due to the missing // shard file, which may have been caused by the test failing before the runner had a chance to // touch the file