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.
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
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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Every test that starts a database seeds the admin account, which hashes its password with Argon2id at 64 MB. Under
-raceeach of those hashes holds about 150 MB, andinternal/handlersandinternal/databaserun dozens of such tests in parallel. That is where the memory went; the product code does not leak.HashPasswordnow hashes with a package-level copy of the default parameters.database.LowerPasswordHashCostForTestlowers its memory cost to 1 MB, and the five test packages that hash (database,handlers,server,gormlog,resetpw) call it from a newTestMain.VerifyPasswordreads the cost from the hash, so verification follows. The shipped parameters andDefaultPasswordConfigare unchanged.TestHashPassword_ShippedParametershashes and verifies once at the shipped 64 MB parameters, so production hashing stays covered.script/testadds-p 4 -parallel 8. Even with cheap hashing, every-racetest 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.
internal/database/testing.go, beside the existing test constructors), because other packages' tests cannot reach anexport_test.go.-p 4also limits compilation, so a cold build cache compiles more slowly.internal/handlers' run time.Model: opus-5-5
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.