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

Implement TEST_PREMATURE_EXIT_FILE #23284

Closed
wants to merge 2 commits into from
Closed
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 @@ -66,6 +66,7 @@
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 @@ -658,7 +659,25 @@ private TestAttemptResult runTestAttempt(
try {
spawnResults = resolver.exec(spawn, actionExecutionContext.withFileOutErr(fileOutErr));
testResultDataBuilder = TestResultData.newBuilder();
testResultDataBuilder.setCachable(true).setTestPassed(true).setStatus(BlazeTestStatus.PASSED);
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);
}
} catch (SpawnExecException e) {
if (e.isCatastrophic()) {
closeSuppressed(e, streamed);
Expand Down
28 changes: 28 additions & 0 deletions src/test/py/bazel/bazel_windows_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,34 @@ def testTestShardStatusFile(self):
['test', '--incompatible_check_sharding_support', '//:foo_test']
)

def testTestPrematureExitFile(self):
lberki marked this conversation as resolved.
Show resolved Hide resolved
self.ScratchFile(
'BUILD',
[
'sh_test(',
' name = "foo_test",',
' srcs = ["foo.sh"],',
')',
],
)
self.ScratchFile(
'foo.sh',
[
'#!/bin/sh',
'touch "$TEST_PREMATURE_EXIT_FILE"',
'echo "fake pass"',
'exit 0',
],
)

exit_code, stdout, stderr = self.RunBazel(
['test', '--test_output=errors', '//:foo_test'],
allow_failure=True,
)
# Check for "tests failed" exit code
self.AssertExitCode(exit_code, 3, stderr, stdout)
self.assertIn('-- Test exited prematurely (TEST_PREMATURE_EXIT_FILE exists) --', stdout)

def testMakeVariableForDumpbinExecutable(self):
if not self.IsWindows():
return
Expand Down
19 changes: 19 additions & 0 deletions src/test/shell/bazel/bazel_test_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1097,4 +1097,23 @@ EOF
//:x &> $TEST_log || fail "expected success"
}

function test_premature_exit_file_checked() {
cat <<'EOF' > BUILD
sh_test(
name = 'x',
srcs = ['x.sh'],
)
EOF
cat <<'EOF' > x.sh
#!/bin/sh
touch "$TEST_PREMATURE_EXIT_FILE"
echo "fake pass"
exit 0
EOF
chmod +x x.sh

bazel test //:x --test_output=errors &> $TEST_log && fail "expected failure"
expect_log "-- Test exited prematurely (TEST_PREMATURE_EXIT_FILE exists) --"
}

run_suite "bazel test tests"
23 changes: 23 additions & 0 deletions src/test/shell/bazel/remote/remote_execution_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3259,6 +3259,29 @@ EOF
//:x &> $TEST_log || fail "expected success"
}

function test_premature_exit_file_checked_remote_download_minimal() {
cat <<'EOF' > BUILD
sh_test(
name = 'x',
srcs = ['x.sh'],
)
EOF
cat <<'EOF' > x.sh
#!/bin/sh
touch "$TEST_PREMATURE_EXIT_FILE"
echo "fake pass"
exit 0
EOF
chmod +x x.sh

bazel test \
--remote_executor=grpc://localhost:${worker_port} \
--remote_download_minimal \
--test_output=errors \
//:x &> $TEST_log && fail "expected failure"
expect_log "-- Test exited prematurely (TEST_PREMATURE_EXIT_FILE exists) --"
}

function test_cache_key_scrubbing() {
echo foo > foo
echo bar > bar
Expand Down
Loading