✨ feat(bdd): parallel-safe schema-per-package isolation (T12 stage 2/2) — 2.85x speedup #35
Reference in New Issue
Block a user
Delete Branch "feat/bdd-parallel-isolation-stage2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Re-enables
BDD_SCHEMA_ISOLATION=truewith the foundation merged in PR #34. Achieves 2.85x speedup on the BDD test suite by running feature packages in parallel.This is the proper architectural answer to the user's request 2026-05-03:
Architecture
When
BDD_SCHEMA_ISOLATION=true, each test PACKAGE (process) gets its own isolated PostgreSQL schema:testserver.Start()generates a deterministic schema name fromFEATUREenvCREATE SCHEMA <name>via the bootstrap repogorm.DBwith DSNsearch_path=<name>AutoMigrateruns in the isolated schema (creates theuserstable)server.Serverviaserver.NewServerWithUserRepoinjecting the isolated repo + user serviceStop()drops the schema + closes the per-package poolPackages then run in parallel (default Go test parallelism,
-p≈ NumCPU) without contention because each has its own schema + connection pool.Why per-PACKAGE and not per-SCENARIO
The previous attempt (PR #26, reverted in PR #28) targeted per-scenario isolation but ran into:
Per-package isolation is simpler and sufficient for parallel
go test ./features/...because each test package runs in its own process. Per-scenario in-process isolation would require dynamic repo replacement mid-process — much more invasive and not needed for current scaling goals.If we ever need per-scenario isolation, the building blocks are ready (
NewPostgresRepositoryFromDSN+BuildSchemaIsolatedDSNfrom PR #34,NewServerWithUserRepohere,Exechelper here).Changes
pkg/server/server.go: NEW factoryNewServerWithUserRepo(cfg, ctx, userRepo, userService). ExistingNewServerbecomes a thin wrapper.pkg/bdd/testserver/server.go:Start()takes the isolated path whenBDD_SCHEMA_ISOLATION=true.Stop()cleans up.pkg/user/postgres_repository.go:Exec(sql)helper for schema lifecycle.scripts/run-bdd-tests.sh:-p 1only whenBDD_SCHEMA_ISOLATION!=true..gitea/workflows/ci-cd.yaml: exportsBDD_SCHEMA_ISOLATION=true.adr/0025-bdd-scenario-isolation-strategies.md: Status updated to Implemented.Validation
5 consecutive runs of AuthBDD with isolation enabled:
Local benchmark on the full
features/...suite:-p 1(no isolation)Speedup: 2.85x on the local 4-core dev machine. CI runners with more cores should see better.
Test plan
go build ./...PASSgo test ./pkg/...PASStime go test ./features/...≈ 4.5s with isolation vs 12.9s sequentialBDD_SCHEMA_ISOLATION=trueOut of scope
FEATUREenv var, falls back tobdd)🤖 Co-Authored-By: Claude Opus 4.7 (1M context)