Keep make test under 2 GB of memory (closes #344) #404

Open
clawbot wants to merge 1 commits from issue-344-test-memory into next
Collaborator

Every test that starts a database seeds the admin account, which hashes its password with Argon2id at 64 MB. Under -race each of those hashes holds about 150 MB, and internal/handlers and internal/database run dozens of such tests in parallel. That is where the memory went; the product code does not leak.

  • HashPassword now hashes with a package-level copy of the default parameters. database.LowerPasswordHashCostForTest lowers its memory cost to 1 MB, and the five test packages that hash (database, handlers, server, gormlog, resetpw) call it from a new TestMain. VerifyPassword reads the cost from the hash, so verification follows. The shipped parameters and DefaultPasswordConfig are unchanged.
  • TestHashPassword_ShippedParameters hashes and verifies once at the shipped 64 MB parameters, so production hashing stays covered.
  • script/test adds -p 4 -parallel 8. Even with cheap hashing, every -race test binary and every link costs a few hundred MB, and the defaults (one per core) let them all run at once.

Before and after figures are on #344.

  • Judgement call: the lowering is an exported function in a non-test file (internal/database/testing.go, beside the existing test constructors), because other packages' tests cannot reach an export_test.go.
  • Judgement call: nothing makes a new test package that starts a database call it; one that does not pays the full 64 MB per start.
  • Judgement call: -p 4 also limits compilation, so a cold build cache compiles more slowly.
  • This also removes the per-test hashing cost that #225 measured as most of internal/handlers' run time.

Model: opus-5-5

Every test that starts a database seeds the admin account, which hashes its password with Argon2id at 64 MB. Under `-race` each of those hashes holds about 150 MB, and `internal/handlers` and `internal/database` run dozens of such tests in parallel. That is where the memory went; the product code does not leak. - `HashPassword` now hashes with a package-level copy of the default parameters. `database.LowerPasswordHashCostForTest` lowers its memory cost to 1 MB, and the five test packages that hash (`database`, `handlers`, `server`, `gormlog`, `resetpw`) call it from a new `TestMain`. `VerifyPassword` reads the cost from the hash, so verification follows. The shipped parameters and `DefaultPasswordConfig` are unchanged. - `TestHashPassword_ShippedParameters` hashes and verifies once at the shipped 64 MB parameters, so production hashing stays covered. - `script/test` adds `-p 4 -parallel 8`. Even with cheap hashing, every `-race` test binary and every link costs a few hundred MB, and the defaults (one per core) let them all run at once. Before and after figures are on https://git.eeqj.de/sneak/webhooker/issues/344. - Judgement call: the lowering is an exported function in a non-test file (`internal/database/testing.go`, beside the existing test constructors), because other packages' tests cannot reach an `export_test.go`. - Judgement call: nothing makes a new test package that starts a database call it; one that does not pays the full 64 MB per start. - Judgement call: `-p 4` also limits compilation, so a cold build cache compiles more slowly. - This also removes the per-test hashing cost that https://git.eeqj.de/sneak/webhooker/issues/225 measured as most of `internal/handlers`' run time. Model: opus-5-5
clawbot added the needs-review label 2026-10-01 22:25:08 +02:00
clawbot self-assigned this 2026-10-01 22:25:08 +02:00
clawbot added 1 commit 2026-10-01 22:25:08 +02:00
Every test that starts a database hashed the bootstrap admin password
with Argon2id at 64 MB, which under -race holds about 150 MB per hash,
across dozens of parallel tests. The test packages that hash now lower
the memory cost to 1 MB from TestMain. One test still hashes and
verifies at the shipped parameters, which are unchanged.

script/test also runs at most four packages and eight parallel tests
at once: unbounded, a many-core host linked and ran every test binary
together.

Model: opus-5-5
Some checks are pending
check / check (push) Waiting to run
This pull request has changes conflicting with the target branch.
  • script/test
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin issue-344-test-memory:issue-344-test-memory
git checkout issue-344-test-memory
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/webhooker#404