Skip to content

CI: cut go test -race time by lowering bcrypt cost in tests#44

Merged
PeterRounce merged 1 commit into
mainfrom
claude/ci-bcrypt-test-cost
Jun 17, 2026
Merged

CI: cut go test -race time by lowering bcrypt cost in tests#44
PeterRounce merged 1 commit into
mainfrom
claude/ci-bcrypt-test-cost

Conversation

@PeterRounce

Copy link
Copy Markdown
Member

Problem

CI / build (push) runs ~3 min and is the gate before docker-card, so it paces the whole pipeline. Per-step timings from recent main runs show the Test step is ~90% of the job:

Step #43 merge #42 merge
setup-go / vet / build 10s 12s
Test (go test -race) 2m55s 3m17s
govulncheck 4s 3s

Within the suite, the web package is ~95% of test time, 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), amplified ~2× by the race detector.

Fix

All hashing routes through one function, so a single knob covers it:

  • web/util.goHashPassword now reads a package var bcryptCost. Production is unchanged (defaults to bcrypt.DefaultCost).
  • web/main_test.go — new TestMain sets bcryptCost = bcrypt.MinCost for the web test package only (~64× fewer rounds). CompareHashAndPassword reads 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)

Before After
web pkg, -race 3m51s 26s
web pkg CPU (user) 3m17s 10.6s
full ./... -race 34s, all green

CI'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

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>
@PeterRounce PeterRounce merged commit c3dcf82 into main Jun 17, 2026
9 checks passed
@PeterRounce PeterRounce deleted the claude/ci-bcrypt-test-cost branch June 17, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant