CI: cut go test -race time by lowering bcrypt cost in tests#44
Merged
Conversation
The `build` job's Test step was ~3 min and gates `docker-card`, pacing the whole pipeline. Per-step timings showed `go test -race -count=1 ./...` is ~90% of the job, the `web` package is ~95% of that, and its slowest tests are all bcrypt-bound: every setupAdminSession hashes a password and the 2FA tests hash 10 recovery codes each at bcrypt.DefaultCost (~80ms/hash), doubled by -race. Route all hashing through a package var `bcryptCost` (production unchanged at bcrypt.DefaultCost) and lower it to bcrypt.MinCost in a web-package TestMain. CompareHashAndPassword reads the cost from the hash, so verification gets cheaper too and the hashing path stays fully exercised. Measured (1-core box): web package -race 3m51s -> 26s; full ./... -race 34s, all green. CI's ~3-min Test step should drop to well under a minute. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
CI / build (push)runs ~3 min and is the gate beforedocker-card, so it paces the whole pipeline. Per-step timings from recentmainruns show the Test step is ~90% of the job:go test -race)Within the suite, the
webpackage is ~95% of test time, and its slowest tests are all bcrypt-bound: everysetupAdminSessionhashes a password, and the 2FA tests hash 10 recovery codes each atbcrypt.DefaultCost(~80ms/hash), amplified ~2× by the race detector.Fix
All hashing routes through one function, so a single knob covers it:
web/util.go—HashPasswordnow reads a package varbcryptCost. Production is unchanged (defaults tobcrypt.DefaultCost).web/main_test.go— newTestMainsetsbcryptCost = bcrypt.MinCostfor the web test package only (~64× fewer rounds).CompareHashAndPasswordreads the cost from the hash, so login/recovery verification gets cheaper too and the hashing path stays fully exercised.Measured (1-core box; CI has 4 cores, ratios hold)
webpkg,-racewebpkg CPU (user)./...-raceCI's ~3-min Test step should drop to well under a minute (race-compile of changed packages becomes the floor).
Version bumped
0.22.2 → 0.22.3(PATCH).🤖 Generated with Claude Code