Repository navigation
perf(tests): copy a migrated template instead of migrating every test - #43
Open
PermutationResearch wants to merge 8 commits into
Open
PermutationResearch wants to merge 8 commits into
PermutationResearch wants to merge 8 commits into
Conversation
PermutationResearch
changed the base branch from
fix/hearth-ci
to
fix/hearth-clippy
December 1, 2026 02:54
PermutationResearch
force-pushed
the
fix/hearth-template-db
branch
from
December 1, 2026 02:54
881a6e2 to
43b52b5
Compare
This was referenced Dec 1, 2026
PermutationResearch
force-pushed
the
fix/hearth-template-db
branch
from
December 1, 2026 03:43
43b52b5 to
2bf23d7
Compare
Every TestDb created an empty database and replayed all 99 migrations, so one test binary of 16 tests spent 113 s of its 8 s of actual work on migrations. The suite is 1,554 tests; this is most of why a full run takes over 40 minutes. Each migration cut is now migrated once into `hearth_tpl_<version>_<digest>` and every test copies it with CREATE DATABASE ... TEMPLATE. The name comes from the cut, so an unchanged schema reuses an earlier run's template, and a changed one builds beside it. Creation is serialised by an advisory lock, the template connection is closed before use (Postgres refuses a template with live connections), and a copy that races another gets 20 bounded retries on "being accessed by other users". A cut with no migrations gets the tag "empty", which is shorter than a digest prefix, so the tag is clamped. Same 16-test binary, same machine, with the four macOS-only `setpriv` tests skipped: 113.31 s -> 15.83 s. Across the whole suite on CI the test bodies went from 1148 s to 506 s.
PermutationResearch
force-pushed
the
fix/hearth-clippy
branch
from
December 1, 2026 04:47
01fdb7f to
92344f2
Compare
PermutationResearch
force-pushed
the
fix/hearth-template-db
branch
from
December 1, 2026 04:47
2bf23d7 to
e71ccd9
Compare
28 of the 31 failing hearth-control tests switch to the restricted serving role and failed with `role "hearth_app" does not exist`: the CI cluster never had it. Create it once, as database-roles.md says, through the service container's psql. purchase_gateway_e2e runs the payments adapter's SDK peer under Node 24+ with its production dependencies and failed on an unset HEARTH_TEST_NODE. Install Node 24 and the adapter's locked production dependencies when integration tests run, and point HEARTH_TEST_NODE at that node.
the_api_needs_a_live_session signed in with `login`, which also opens a browser session, so `call` sent the cookie to /auth/logout. That route ends CLI sessions and reads only a bearer, so it answered 401. Sign in with `login_cli`, as the test means a CLI session. the_scanner_knows_the_stores_the_database_lets_it_redact compared a byte-sorted list with one sorted by the cluster's default collation. Under en_US.utf8, as in CI, `thread_renders` sorts before `thread_render_snapshots`. Order the query by COLLATE "C".
migrate grants hearth_app its rights only if the role exists. The template name came from the migration cut alone, so a template built before an operator created the role kept being copied without those grants, and the restricted-role tests failed on that machine. Record the role's existence in the template name.
Publication fast-forwards with `git merge` through a throwaway git directory removed by an EXIT trap. After a merge, Git runs automatic maintenance and by default detaches it into the background, where it can still be writing in that directory while the trap removes it. Under `set -euo pipefail` the failed `rm -rf` exits 1, so a completed publication reports as refused. CI on Git 2.56.1 hit this once (fleet_integration's sequential merge test: "rm: cannot remove '/tmp/tmp.…': Directory not empty", then status 1); the same test passed on the previous run. Not reproduced locally on Git 2.50.1. Pass maintenance.auto=false to the view's git.
Since "Decisions and anything that widens authority need a browser", sharing a machine and approving a purchase refuse a CLI token. Two tests still sent one, hidden until now behind the missing hearth_app role and Node: - workspace_reviews granted Bob access with Alice's bearer over HTTP. Grant through Harness::call, which sends her browser session, as the fixture's own setup already does. - purchase_gateway_e2e's SDK peer approved purchases with the bearer. Pass Alice's browser headers to the peer and approve with them; the agent side keeps its token.
The key was Cargo.lock alone, so a cache saved by a run that built one package was an exact hit for a run that builds the whole workspace. An exact hit skips the save, so #43's whole-workspace runs restored a hearth-control-only target, rebuilt most crates (33 min) and saved nothing. Work out the scope before restoring and add a hash of it to the key. A run whose scope has no cache yet restores the newest cache for the same Cargo.lock, builds the rest and saves its own. The prefix stays v2: existing v2 entries are complete for their scope and remain useful fallbacks.
An exact hit on the whole-workspace cache still took 29m50s to build the test binaries, against 26m52s from a partial fallback: checkout gives workspace sources new timestamps, so Cargo rebuilds all 25 workspace crates on every run. Their artifacts doubled the entry to 6 GB and its restore to four minutes without saving any build time. Drop workspace artifacts with cargo clean -p before saving. The test binaries are workspace artifacts, so the save moves after the tests and runs whenever the build succeeded, failing tests included. Bump the key to v3 so the full v2 entry is never restored again.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every
TestDbcreated an empty database and replayed all 99 migrations. On one 16-test binary that was 113.31 s of migrations for 8 s of test work — and the workspace suite is 1,554 tests across 139 binaries, which is most of why a full run passes 40 minutes.What changed
crates/hearth-control/tests/common/mod.rsonly:hearth_tpl_<version>_<digest>;CREATE DATABASE … TEMPLATEinstead ofCREATE DATABASE+db::migrate_with;is being accessed by other users.No change to isolation: every test still gets its own database and drops it (including on panic), and
TestDb::existing, partial-migration cuts andHEARTH_TEST_DATABASE_ROLEall behave as before.Measured here
Same machine, same binary (
approval_rules, 16 tests, four macOS-onlysetprivtests skipped):CREATE DATABASE+ migrate per test)7.2× on the test body. The expected effect on CI is the same order: migrations were per test, not per run.
Notes
hearth_tpl_<version>_<digest>), by design: dropping them would race another test binary of the same run. They are a few MB each and reused across runs.approval_rulestests fail on macOS before and after this change: the fixture shells out to/usr/bin/setpriv, which Linux has and macOS does not.