Skip to content

Shard jsg-test's Rust tests between Bazel test shards - #8856

Merged
danlapid merged 1 commit into
mainfrom
dlapid/shard-rust-tests
Nov 25, 2026
Merged

danlapid merged 1 commit into
mainfrom
dlapid/shard-rust-tests

Conversation

@danlapid

@danlapid danlapid commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

jsg-test has more than a thousand tests. Each one creates a V8 isolate, and like every Rust test here they run serially (RUST_TEST_THREADS=1). No single case is slow: each takes about 26 ms, nearly all of it isolate setup. Together they took about a minute in a debug build and longer under TSan, so the target was declared enormous.

libtest can't shard and neither can rules_rust's rust_test, so this adds sharding to the macros:

  • wd_rust_test takes a shard_count, which wd_rust_crate passes on as test_shard_count. The rust_test becomes the manual target <name>@unsharded, and <name> is a test that runs it through //build/rust/test_sharder.
  • The sharder is a small Rust binary, so it also works on Windows. It lists the libtest tests, keeps every TEST_TOTAL_SHARDS-th one starting at TEST_SHARD_INDEX, and runs those by exact name. The names are passed in batches that fit a Windows command line. Its arguments are passed on to the test binary, so --test_arg filters still narrow the list.
  • Each shard is its own process and still runs its tests serially. Tests that share process-wide state, such as static drop counters and autogates, keep working.
  • The sharded test forwards the inner test's clippy_checks and rustfmt_checks output groups. Without that, the lint aspects would never reach the manual inner target.

jsg-test now uses 8 shards and is large. Timings on remote execution, over 40 shard runs (5 runs of 8 shards):

config unsharded sharded (max / avg)
debug 59.6 s 19.1 s / 10.0 s
TSan 68.5 s 17.9 s / 12.8 s
ASan 9.0 s / 5.1 s

The 8 shards together run all 1156 tests, each exactly once.

Not tested on Windows or macOS. CI here covers both.

🤖 Generated with Claude Code

@danlapid
danlapid force-pushed the dlapid/shard-rust-tests branch from 3974be0 to 5d826e3 Compare November 24, 2026 04:44
@codecov-commenter

codecov-commenter commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.54%. Comparing base (cf343ed) to head (ab98e49).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8856   +/-   ##
=======================================
  Coverage   67.54%   67.54%           
=======================================
  Files         871      871           
  Lines      220219   220219           
  Branches    32916    32916           
=======================================
+ Hits       148739   148740    +1     
  Misses      52041    52041           
+ Partials    19439    19438    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

jsg-test has more than a thousand tests. Each creates a V8 isolate,
and like every Rust test here they run serially
(RUST_TEST_THREADS=1), so the crate's test took about a minute in a
debug build and longer under TSan, with no single slow case: about
26 ms per case, nearly all of it isolate setup. It was declared
`enormous` to fit.

libtest has no sharding of its own and rules_rust's rust_test does
not shard either, so wd_rust_test gets a shard_count, which
wd_rust_crate passes on as test_shard_count. The rust_test then
becomes the manual target <name>@unsharded, and <name> is a test
that runs it through //build/rust/test_sharder. That Rust binary
lists the libtest tests, keeps every TEST_TOTAL_SHARDS-th one from
TEST_SHARD_INDEX, and runs those by exact name, in batches that fit
a Windows command line. Each shard is a process of its own and still
runs its tests serially, so tests that share process-wide state
(static drop counters, autogates) keep working. The sharded test
forwards the inner test's clippy and rustfmt checks, which the lint
aspects would otherwise never reach on a manual target.

jsg-test uses 8 shards and is now `large`. On remote execution, over
40 shard runs each, shards take 10 s on average and at most 19 s in a
debug build (the unsharded test took 60 s), and 13 s on average and
at most 18 s under TSan (69 s).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@danlapid
danlapid force-pushed the dlapid/shard-rust-tests branch from 5d826e3 to ab98e49 Compare November 25, 2026 03:18
@danlapid
danlapid marked this pull request as ready for review November 25, 2026 19:51
@danlapid
danlapid requested review from a team as code owners November 25, 2026 19:51

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Approved with comments — The sharding is correct for jsg-test. The two notes are latent edge cases: env values are not location-expanded on the sharded wrapper, and a positional --test_arg filter turns into an exact match once the sharder adds --exact.

Findings: 2 info (2 are inline comments on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 2 info

The sharder and macro look correct. Two low-impact edge cases.

Recommendation: 💬 Optional Nits

  • [INFO] The sharded test's env is passed as given, without the location expansion that rust_test applies to its env. (build/wd_rust_test.bzl:43)
  • [INFO] A positional --test_arg filter becomes an exact-name filter in the shard run because --exact is appended. (build/rust/test_sharder/sharder.rs:130)
View full review
  • The sharded wrapper sets env as given, with no $(location ...) / $(rootpath ...) expansion. The inner rust_test does get expanded values, but it inherits the wrapper's environment when the sharder starts it.
  • A positional filter passed with --test_arg matches by substring when the sharder lists the tests. In the actual run it becomes an exact-name filter, because --exact is added.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security concerns in the sharder or the Bazel rule changes.


📖 AGENTS.md: ✅ LGTM

No issues found.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The shard_count docstring and the checklist addition describe the behaviour accurately.


Reviewed commit: ab98e497

Comment thread build/wd_rust_test.bzl Resolved
Comment thread build/rust/test_sharder/sharder.rs Resolved
@danlapid
danlapid enabled auto-merge (rebase) November 25, 2026 20:04
@danlapid
danlapid disabled auto-merge November 25, 2026 20:04
@danlapid
danlapid merged commit 51d71a7 into main Nov 25, 2026
23 of 24 checks passed
@danlapid
danlapid deleted the dlapid/shard-rust-tests branch November 25, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants