Merge pull request 'ci: shard test job + cheap argon2 in test mode' (#13) from ci-faster-tests into main

Reviewed-on: #13
This commit was merged in pull request #13.
This commit is contained in:
2026-05-05 07:44:30 +00:00
2 changed files with 48 additions and 4 deletions
+29 -2
View File
@@ -53,8 +53,24 @@ env:
jobs: jobs:
test: test:
name: Test (linux/amd64) # Sharded by package group. server/http and store are the two
# heavy packages (~156s and ~75s in CI respectively under
# `-race`); pulling them onto their own runners lets each shard
# have all CPUs to itself instead of CPU-starving each other on
# one runner. The third shard ("rest") covers everything else.
name: Test (${{ matrix.name }})
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: server-http
packages: ./internal/server/http/...
- name: store
packages: ./internal/store/...
- name: rest
# Computed at runtime — see the "go test" step below.
packages: ""
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-go@v5 - uses: actions/setup-go@v5
@@ -64,7 +80,18 @@ jobs:
- name: go vet - name: go vet
run: go vet ./... run: go vet ./...
- name: go test - name: go test
run: go test -race -coverprofile=coverage.out ./... run: |
set -euo pipefail
if [ -n "${{ matrix.packages }}" ]; then
pkgs="${{ matrix.packages }}"
else
# "rest" shard: everything except the dedicated shards.
pkgs=$(go list ./... \
| grep -v '/internal/server/http$' \
| grep -v '/internal/store$')
fi
# shellcheck disable=SC2086
go test -race -coverprofile=coverage.out $pkgs
- name: coverage summary - name: coverage summary
run: go tool cover -func=coverage.out | tail -1 run: go tool cover -func=coverage.out | tail -1
+19 -2
View File
@@ -9,6 +9,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
"testing"
"golang.org/x/crypto/argon2" "golang.org/x/crypto/argon2"
) )
@@ -27,22 +28,38 @@ const (
defaultKeyLen = 32 defaultKeyLen = 32
) )
// Cheap params used only when the binary is a `go test` binary
// (testing.Testing() == true). Argon2id at production params costs
// 300500 ms per hash and dominates wall time on CI runners under
// `-race`. Tests don't need real KDF strength — VerifyPassword reads
// params from the encoded hash, so verifying a cheap-params hash
// works the same way.
const (
testMemoryKiB = 8
testIterations = 1
testParallel = 1
)
// HashPassword returns an argon2id-encoded string of the form // HashPassword returns an argon2id-encoded string of the form
// //
// $argon2id$v=19$m=...,t=...,p=...$<salt>$<hash> // $argon2id$v=19$m=...,t=...,p=...$<salt>$<hash>
// //
// safe to store in a TEXT column. The salt is freshly random per call. // safe to store in a TEXT column. The salt is freshly random per call.
func HashPassword(password string) (string, error) { func HashPassword(password string) (string, error) {
mem, iter, par := uint32(defaultMemoryKiB), uint32(defaultIterations), uint8(defaultParallel)
if testing.Testing() {
mem, iter, par = testMemoryKiB, testIterations, testParallel
}
salt := make([]byte, defaultSaltLen) salt := make([]byte, defaultSaltLen)
if _, err := rand.Read(salt); err != nil { if _, err := rand.Read(salt); err != nil {
return "", fmt.Errorf("auth: read salt: %w", err) return "", fmt.Errorf("auth: read salt: %w", err)
} }
hash := argon2.IDKey([]byte(password), salt, hash := argon2.IDKey([]byte(password), salt,
defaultIterations, defaultMemoryKiB, defaultParallel, defaultKeyLen) iter, mem, par, defaultKeyLen)
return fmt.Sprintf("$argon2id$v=%d$m=%d,t=%d,p=%d$%s$%s", return fmt.Sprintf("$argon2id$v=%d$m=%d,t=%d,p=%d$%s$%s",
argon2.Version, argon2.Version,
defaultMemoryKiB, defaultIterations, defaultParallel, mem, iter, par,
base64.RawStdEncoding.EncodeToString(salt), base64.RawStdEncoding.EncodeToString(salt),
base64.RawStdEncoding.EncodeToString(hash), base64.RawStdEncoding.EncodeToString(hash),
), nil ), nil