Skip to content

Commit

Permalink
Fix checking TEST_PREMATURE_EXIT_FILE
Browse files Browse the repository at this point in the history
`TEST_PREMATURE_EXIT_FILE` was not cleaned up between test attempts (--flaky_test_attempts).

Fixes bazelbuild#24655

Closes bazelbuild#24657.

PiperOrigin-RevId: 705495967
Change-Id: Ic4d4be1e72230c3a6bc45c9f372d1188fefad201
  • Loading branch information
meteorcloudy authored and bazel-io committed Dec 12, 2024
1 parent 611c425 commit 7ba1d87
Showing 1 changed file with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 7ba1d87

Please sign in to comment.