fix(test): skip redundant Alembic migration check for existing test databases #727

Merged
CoreRasurae merged 1 commits from fix/test-db-performance-regression into master 2026-03-12 13:20:14 +00:00

1 Commits

Author SHA1 Message Date
CoreRasurae 1ec525599b fix(test): skip redundant Alembic migration check for existing test databases
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 14s
CI / build (pull_request) Successful in 16s
CI / quality (pull_request) Successful in 19s
CI / security (pull_request) Successful in 36s
CI / typecheck (pull_request) Successful in 38s
CI / unit_tests (pull_request) Successful in 2m59s
CI / docker (pull_request) Successful in 10s
CI / integration_tests (pull_request) Successful in 3m28s
CI / coverage (pull_request) Successful in 6m35s
CI / benchmark-regression (pull_request) Successful in 35m34s
CI / lint (push) Successful in 12s
CI / build (push) Successful in 14s
CI / quality (push) Successful in 16s
CI / security (push) Successful in 35s
CI / typecheck (push) Successful in 36s
CI / benchmark-regression (push) Has been skipped
CI / unit_tests (push) Successful in 3m6s
CI / docker (push) Successful in 10s
CI / integration_tests (push) Successful in 3m26s
CI / coverage (push) Successful in 5m22s
CI / benchmark-publish (push) Successful in 19m46s
When a test database already exists and is non-empty (created by a prior
step like `I have initialized a project`), _fast_init_or_upgrade in
features/environment.py was falling through to _original_init_or_upgrade,
running a full Alembic migration version check every time.  This created
redundant SQLAlchemy engines, caused SQLite lock contention under
parallel execution, and triggered cumulative overhead from @database_retry
decorators (wait_fixed(0.5) × 3 attempts on ~100 repository methods),
leading to intermittent hangs and CI timeouts.

The fix changes the existing-non-empty-database branch to return
immediately instead of delegating to the original migration runner.
This is safe because test databases are either template-copied (already
at Alembic HEAD) or created by a prior step that already ran the full
migration.  The _SCENARIO_DB_PREFIXES guard ensures non-scenario
databases (migration-runner unit tests) remain unaffected.

Verified: 15/15 scenarios pass with both --processes 1 and --processes 16.

ISSUES CLOSED: #726
2026-03-12 12:39:49 +00:00