ozone: speed up slow integration tests by matthieusieben · Pull Request #6053 · bluesky-social/atproto
Pull request (OPEN) · PR #6053 ozone: speed up slow integration tests · @matthieusieben The ozone jest suite is now the CI critical path (1064s → 1948s across the 8 shards since Oct 9). Five report-heavy files account for most of the growth, and the largest one alone pins a shard. This PR cuts their cost and splits the three largest so the shard balancer can spread them. Test-only: packages/ozone/src is untouched.
Root cause (profiled)
I profiled the five files with a throwaway jest setup file that wrapped TestNetwork.processAll and its stages, the seed client, the moderator client, and fetch (per XRPC method). Findings for report-close-reports (63 tests, ~90s locally):
326 network.processAll() calls, ~30s. The report() helper flushed the whole network after every report, and the other files also flushed after every fixture. Each flush costs 80–100ms: ~45ms in processFullSubscription polling for AppView catch-up, ~20ms ozone team-profile sync (an AppView getProfiles round trip), and ~10ms queue routing. A new report doesn't need most of that. ModerationService.logEvent inserts the report row in the same transaction as its event ( src/mod-service/index.ts ), so the only daemon work needed before reading it is queue routing , which also sets queueId / updatedAt .
312 queryReports lookups, ~10s. Each report was resolved with its own queryReports , and each call hydrates rows through AppView getProfiles / getAccountInfos / queryLabels / getRecord . Some call sites didn't scope by subject, and reportForEvent scanned open +muted before queued , so a queued report took 3 queries.
One 7000-report test took 6–22s , depending on whether autoanalyze had run. The bulk SQL fixture lands in a near-empty table, so the closure runs on stale plans. With ANALYZE it takes ~2s (3 runs each way).
Everything else is the tests' own reads and assertions ( getReport hydration ~35ms each, listActivities , closeReports ). I left those alone.
So the per-item processAll hypothesis was right, but it was about a third of the time. The per-report lookups, the 7000-row test, and one file pinning a shard mattered too.
Changes
tests/_inbox.ts
createReports(network, sc, inputs) files reports in order , runs one queueRouter.routeReports() pass (the same call processAll makes), then resolves every view with one did -scoped queryReports per status ( reportsForEvents ).
pooled(create, flush) creates fixtures (account + posts) in batches of 8 that share one network.processAll() . Each fixture is still used by exactly one test.
reportForEvent checks unmuted statuses first. A report matches exactly one status/muted pair, so results are identical; it just takes fewer queries.
File (tests)
Change
report-close-reports (63)
Batched reports and pooled fixtures. Split into report-close-reports (explicit targeting / exact scope, 15), -active-review (8), -reasons (owned-subject protection + reason filters, 18) and -links (action links, legacy and bulk tests, 22), with shared setup in tests/_close-reports.ts . ANALYZE report, moderation_event after the 7000-row fixture.
report-account-actions (68)
Batched reports and pooled fixtures. Split into report-account-actions (targeting, 29) and -validation (rejections, explicit IDs, rollbacks, 39), with shared setup in tests/_account-actions.ts .
report-action-no-matches (63)
Batched reports and pooled fixtures. Split into report-action-no-matches (35) and -closure (types/all closure selectors, 28), with shared setup in tests/_report-action-matching.ts .
appeal-actioned-subject (81)
Appeal lookups scoped to the appellant DID or the subject. Back-to-back identical latestAppealReport() reads merged into one.
moderation-bulk-events (52)
Batched reports and pooled fixtures. Lookups are DID-scoped instead of scanning every open report.
Every split file has its own dbPostgresSchema .
Measurements
These are local numbers (12-core Mac). Postgres was shared with another agent running the bsky suite, so absolute times move by ±30% between runs. To get a fair comparison, each row ran the original file and the rewritten files at the same time, on separate fresh databases , so both sides saw the same load. Two samples, run 1 / run 2 , in seconds ( cd packages/ozone && DB_POSTGRES_URL=…/<fresh db> REDIS_HOST=… NODE_OPTIONS=--experimental-vm-modules pnpm exec jest --maxWorkers=1 <files> --json ):
Original file (CI before)
Before, local
After, per file
After, sum
report-close-reports (235s)
114.8 / 87.4
base 18.9 / 13.0 · -active-review 19.5 / 13.6 · -reasons 26.0 / 22.8 · -links 17.2 / 15.1
81.6 / 64.5
report-account-actions (125s)
89.2 / 71.4
base 35.7 / 27.6 · -validation 23.8 / 19.8
59.5 / 47.4
report-action-no-matches (101s)
64.2 / 39.8
base 23.4 / 14.0 · -closure 27.9 / 20.7
51.3 / 34.7
appeal-actioned-subject (61s)
25.3 / 21.4
22.0 / 18.4
22.0 / 18.4
moderation-bulk-events (49s)
22.4 / 20.6
15.7 / 15.5
15.7 / 15.5
Total
315.9 / 240.6
230.1 / 180.5 (−27% / −25%)
Largest single file
114.8 / 87.4
35.7 / 27.6 (−69% / −68%)
The total includes ~3s of network setup for each of the 6 new files. The work reduction is easier to see in the round trips (single-file profiles, before → after):
File
network.processAll
queryReports
report-close-reports
326 → 23
312 → 66
report-account-actions
388 → 15
296 → 83
report-action-no-matches
210 → 13
145 → 71
appeal-actioned-subject
4 → 4
162 → 108
moderation-bulk-events
88 → 10
41 → 14
I ran the whole ozone suite the way CI does ( --maxWorkers=1 --shard=k/8 for k = 1..8, fresh database each): 107 suites, 1398 tests passed, 0 failed. The one skipped test is a pre-existing it.skip in moderation.test.ts . Shard assignment differs locally from CI, so this PR's CI run is the real shard-balance number.
I left the next tier alone ( queue-tag-routing , report-reason , report-assignment , queue-strict-access , moderation , report-metadata , inbox-appeal-outcomes , report-activity , query-reports ). Profiled locally they take 5–14s each, network setup (~3s) is their largest single cost, and the rest is spread across assertion calls. They still benefit from the cheaper reportForEvent .
Coverage
Assertions and coverage are unchanged: every it still runs with the same assertions against the same endpoints. Test names match the originals exactly; only the root describe differs for split files. Across the five original files, 327 tests still run, checked by comparing the jest JSON name lists. The setup changes:
Consecutive report creation is batched. Where a test interleaved creating reports with status changes, it now files all reports first, in the original order (so report IDs keep their relative order), then applies the status changes in the original order. This doesn't change the outcome: reportRowFromEvent always starts a report open and unassigned, and routing depends only on queues and tags. Every snapshot a test compares against is still taken after routing.
Fixtures (accounts and posts) are created ahead of use, in batches of 8.
Two pairs of back-to-back identical reads were merged into one read ( detail(r.id) twice in a row, and latestAppealReport() twice in a row). They assert the same fields on the same unchanged state.
The bulk test's ANALYZE only refreshes planner statistics.
🤖 Generated with Claude Code Ouvrir sur GitHub →