Skip to content

Commit

Permalink
Actually check TEST_SHARD_STATUS_FILE has been touched
Browse files Browse the repository at this point in the history
Adds the missing check that a test runner running a sharded test
actually supports sharding. Previously, if it didn't, each shard would
silently run all tests.

RELNOTES: If sharding is requested for a test but the test runner does
not advertise support for test sharding by touching the
`TEST_SHARD_STATUS_FILE`, the tests will fail instead of silently
running all tests in each shard.
  • Loading branch information
fmeum committed Apr 27, 2023
1 parent 31c5a72 commit e7f0a5c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/test/py/bazel/bazel_windows_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,31 @@ def testZipUndeclaredTestOutputs(self):
self.assertTrue(os.path.exists(output_file))
self.assertFalse(os.path.exists(output_zip))

def testTestShardStatusFile(self):
self.CreateWorkspaceWithDefaultRepos('WORKSPACE')
self.ScratchFile(
'BUILD',
[
'sh_test(',
' name = "foo_test",',
' srcs = ["foo.sh"],',
' shard_count = 2,',
')',
],
)
self.ScratchFile('foo.sh')

exit_code, _, stderr = self.RunBazel(['test', '//:foo_test'])
# Check for "tests failed" exit code
self.AssertExitCode(exit_code, 3, stderr)
self.assertIn("Sharding requested, but the test runner did not advertise "
"support for it by touching TEST_SHARD_STATUS_FILE.", stderr)

self.ScratchFile('foo.sh', ['touch "$TEST_SHARD_STATUS_FILE"'])

exit_code, _, stderr = self.RunBazel(['test', '//:foo_test'])
self.AssertExitCode(exit_code, 0, stderr)


if __name__ == '__main__':
unittest.main()
20 changes: 20 additions & 0 deletions src/test/shell/bazel/bazel_test_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -997,4 +997,24 @@ EOF
expect_log "<testcase name=\"x\""
}

function test_shard_status_file_checked() {
cat <<'EOF' > BUILD
sh_test(
name = 'x',
srcs = ['x.sh'],
shard_count = 2,
)
EOF
touch x.sh
chmod +x x.sh

bazel test //:x --test_output=errors &> $TEST_log \
&& fail "expected failure"
expect_log "Sharding requested, but the test runner did not advertise support for it by touching TEST_SHARD_STATUS_FILE."

echo 'touch "$TEST_SHARD_STATUS_FILE"' > x.sh
bazel test //:x --test_output=errors &> $TEST_log \
|| fail "expected success"
}

run_suite "bazel test tests"

0 comments on commit e7f0a5c

Please sign in to comment.