Repository navigation
Speed up the Python tests in debug and sanitizer builds - #8860
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8860 +/- ##
==========================================
+ Coverage 67.53% 69.87% +2.33%
==========================================
Files 871 881 +10
Lines 220178 231888 +11710
Branches 32916 33652 +736
==========================================
+ Hits 148700 162026 +13326
+ Misses 52041 49899 -2142
- Partials 19437 19963 +526 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
af8e477 to
458323d
Compare
The asgi Python test slept 20 seconds twice to let the event loop log an error, so every run took over 40 seconds in every build. The log handler now sets an event when it receives an ERROR record, and the test waits on that. An error after the response is logged before asgi.fetch() returns, and a failed background task is logged by its done callback a few event loop turns later. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tester closed its WebSocket, but the Durable Object never replied to the Close frame, so the test request stayed open until the idle Durable Object was evicted 10 seconds later. The Durable Object now closes its end in webSocketClose(), and the tester waits for the close event. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
V8 tiers hot Wasm functions up to TurboFan on background threads. Most Python tests start Pyodide from a memory snapshot and then run little Python, so that compilation rarely pays for itself, while the tests are scheduled as using one CPU. In debug and TSan builds, where V8's compilers are slow, a workerd run of these tests used 1.3 to 2.5 times the CPU time it uses with --liftoff-only, and its wall time on an idle machine was about the same. On a busy machine the extra threads only compete with other tests. Runs that start Pyodide without a snapshot run more Python and take somewhat longer on an idle machine, but still use less CPU. The JSPI and stack-switching tests keep V8's default tiering, so that stack switching stays covered with TurboFan code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When Bazel runs a test in shards (shard_count), it tells each shard its index and the shard count in TEST_SHARD_INDEX and TEST_TOTAL_SHARDS, and expects the runner to touch TEST_SHARD_STATUS_FILE to show that it shards. workerd test now does that and runs only every n-th test case, so that a wd_test whose cases are slow can spread them over several processes. A shard left without cases, when there are fewer cases than shards, passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each of its four cases starts Pyodide from scratch in a dynamic Worker, which takes several seconds in debug and sanitizer builds, so the test took 25-40 seconds there. It now runs each case in a shard of its own, and, like the other Python tests, runs Wasm with Liftoff only, so a shard needs one CPU rather than two. It also reads the Pyodide bundles from the disk cache that py_wd_test provides, through the new PYODIDE_BUNDLE_ARGS and PYODIDE_BUNDLE_DATA, rather than downloading them, so it no longer needs network access. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0.26.0a2 can't stack a snapshot on its baseline snapshot, so every 0.26.0a2 variant of a py_wd_test created its snapshot by starting Pyodide from scratch, which takes over 10 CPU-seconds in debug builds and made these variants the slowest Python tests. They now only load the baseline snapshot, in a single workerd run. The hello test keeps the from-scratch path for 0.26.0a2, through the new create_0_26_snapshot_from_scratch parameter, so that creating a 0.26.0a2 snapshot and restoring it stay covered. It is the smallest worker whose top level runs checks while the snapshot is collected and whose handler runs after the restore. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
458323d to
3ce1722
Compare
There was a problem hiding this comment.
Superseded by the review of
008e0571.
This review, of 3ce1722e
💬 Approved with comments — The changes to the test infrastructure and the new Bazel sharding support look correct. The only note is an optional suggestion to unit-test the shard environment-variable parsing.
Findings: 1 suggestion (1 is an inline comment 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: 💬 1 suggestion
The changes look correct. Optional: add a unit test for the shard environment-variable parsing.
Recommendation: 💬 Optional Nits
- [SUGGESTION] bazel_test_shard() has no unit tests; only shard_cases() does. (
src/workerd/server/server/run.rs:739)
View full review
run-test.rstestsshard_casesbut notbazel_test_shard(). That function holds the protocol handling: both variables must be present, the status file is touched, the values are parsed andindex >= totalis rejected. Moving the string-to-(index, total)parsing into a pure helper would make it testable without changing process environment variables.
These parts were checked and look correct: the shard assignment is deterministic, a shard with no cases passes while an unmatched pattern still fails, the 0.26.0a2 variants load a real baseline snapshot, --liftoff-only is applied consistently, and the asgi and WebSocket test changes are sound.
✅ All other checks passed
🔒 Security: ✅ LGTM
The change only touches test infrastructure. The shard values come from environment variables set by the test runner, and they are validated before use. The status file is only created or touched.
📖 AGENTS.md: ✅ LGTM
No issues found.
⚡ Performance: ✅ LGTM
No issues found.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: 3ce1722e
Move the parsing of TEST_SHARD_INDEX and TEST_TOTAL_SHARDS out of bazel_test_shard() into parse_shard(), which takes the values rather than reading the environment, and test that it parses valid values and refuses non-numbers and an index that isn't below the total. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Superseded by the review of
de3bf5ee.
This review, of 008e0571
✅ Approved — No findings: the one earlier suggestion, unit tests for the shard-variable parsing, is fixed by parse_shard() and its new tests.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
This pull request only changes test infrastructure. Bazel's test runner sets the shard variables, and they are checked before use. The shard status file is only created or touched.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
The earlier suggestion is fixed: parse_shard() holds the parsing and the index < total check, and run-test.rs tests it.
I checked these parts and found nothing wrong:
- Sharding: a shard with no cases passes, and a pattern that matches nothing still fails.
- Bundle loading:
PYODIDE_BUNDLE_ARGSandPYODIDE_BUNDLE_DATAare reused correctly insrc/workerd/api/tests/BUILD.bazel. - asgi and WebSocket tests: the asgi wait-for-error change and the WebSocket close handshake work as described.
- 0.26.0a2 variants: they load the baseline snapshot, and
hellokeeps the path that creates its snapshot from scratch.
⚡ Performance: ✅ LGTM
No issues found.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: 008e0571
hoodmane
left a comment
There was a problem hiding this comment.
LGTM aside from the question about test coverage for baseline snapshot creation.
Instead of sharding the test, define a target per case that selects it with `workerd test`'s filter, so the cases still run in parallel without `workerd test` needing to know about Bazel's sharding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
workerd test read TEST_SHARD_INDEX and TEST_TOTAL_SHARDS from its own environment, so it also sharded the cases of tests that shard themselves: a sharded C++ test that runs `workerd test` in its own process lost cases, and a wd_test whose harness divides its work between shards (wd_test's supports_sharding) ran only part of its cases in each shard. Its one user now runs each case as a separate target instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each py_wd_test variant of a newer Pyodide version stacks a dedicated snapshot on the released baseline one, so no test created a baseline snapshot in those versions, and the 0.26.0a2 variants now load the released one too. py_wd_test's create_baseline_snapshot makes every variant start Pyodide from scratch, create a baseline snapshot and restore it, and top-level-entropy-create-baseline uses it: its top level runs after the restore, as it does in top-level-entropy-baseline. hello no longer needs the 0.26.0a2-only option this replaces. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
✅ Approved — No findings. The changes since the last review (create_baseline_snapshot, a target per worker-loader case, sharding removed from workerd test) look correct, and the earlier suggestion stays fixed.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The pull request only changes test macros, .wd-test configs and test workers. It adds no secrets and changes no access control. The worker-loader test now reads the Pyodide bundles from the local disk cache, so it no longer needs network access.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
The changes since the last review in src/pyodide/tests/BUILD.bazel, src/pyodide/tests/py_wd_test.bzl and src/workerd/api/tests/BUILD.bazel look correct.
create_baseline_snapshot: it setsuse_snapshot = Noneand keepsmake_snapshot, so the snapshot test still runs. In that casepython_dedicated_snapshotis not added, which is correct.- 0.26.0a2 variants: they load the baseline snapshot with
make_snapshot = False. - Per-case worker-loader targets: the four case names match the exports in
worker-loader-python-test.js. Theservice:entrypointfilter is a formatworkerd testaccepts. Only one target lints the shared source file. - Bundle arguments:
PYODIDE_BUNDLE_ARGSandPYODIDE_BUNDLE_DATAuse absolute labels, so they resolve fromsrc/workerd/api/tests. - asgi: the error-wait timeout is caught, so the existing assertions still report a failure.
On the question in the discussion about coverage for creating a baseline snapshot: the new top-level-entropy-create-baseline target covers it in every Pyodide version.
⚡ Performance: ✅ LGTM
No issues found.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: de3bf5ee
The Python tests are among the slowest in the debug and sanitizer builds. Each commit fixes one cause:
--liftoff-only, a workerd run in debug and TSan builds uses 1.3 to 2.5 times less CPU, and its wall time on an idle machine stays about the same. The JSPI and stack-switching tests keep V8's default tiering.workerd test's filter, so they run in parallel, and the test reads the Pyodide bundles from the disk cache thatpy_wd_testuses rather than downloading them, so it no longer needs network access.top-level-entropy-create-baselinetarget (create_baseline_snapshotinpy_wd_test) starts Pyodide from scratch, creates a baseline snapshot and restores it, in every version.The table compares typical (median) times before this change with the average and worst of 5 runs after it. The "after" runs covered every Python test and variant at once, about 800 runs sharing the executors:
Loading the baseline snapshot halved the 0.26.0a2 variants, measured in a separate 5-run pass: debug average 19.9 s → 10.0 s, worst run 26.9 s → 15.9 s; TSan average 14.7 s → 9.2 s.
top-level-entropy-create-baselineaverages 20–26 s per version in debug builds and 15–27 s in TSan over 5 runs; the worker-loader-python-test figures come from the same, more heavily loaded pass, in which evenhello_0.28.2(about 7 s on an idle executor) had runs of over 30 s.🤖 Generated with Claude Code