perf(tests): optimize medium-slow BDD features (10-100s tier)

Cap time.sleep and asyncio.sleep globally at 10ms in before_all to
eliminate retry/backoff waits (tenacity wait_fixed, retry_auto_debug
exponential backoff). Save originals as time._original_sleep and
asyncio._original_sleep for tests that need real wall-clock delays
(CircuitBreaker recovery, debounce timers, validation timeouts).

Enhance template-DB patch: add "db." prefix to _SCENARIO_DB_PREFIXES
and check db_path.stat().st_size > 0 so 0-byte auto-created SQLite
files receive the template copy instead of falling through to real
migrations.

Replace subprocess.run CLI invocations with typer.testing.CliRunner
in module_coverage, main_coverage_complete, and coverage_extras step
files, eliminating ~6s Python cold-start overhead per call.

Switch plan_persistence and action_persistence to in-memory SQLite by
default; only cross-restart scenarios use file-based via an explicit
Given step.

Replace MigrationRunner.run_migrations with Base.metadata.create_all
in plan_service_steps for freshly created in-memory engines.

Removed leftover debug comment in environment.py.

Total tier runtime: 565s -> 21s (96% reduction), 20 features all
under 5s behave-internal time.

ISSUES CLOSED: #480
This commit is contained in:
2026-03-01 23:30:38 +00:00
committed by Forgejo
parent 0bbec4b77e
commit 4ad51561fc
15 changed files with 221 additions and 100 deletions
+10 -2
View File
@@ -344,8 +344,16 @@ def step_create_open_circuit_breaker(context):
@when("the recovery timeout expires")
def step_wait_recovery_timeout(context):
"""Wait for recovery timeout."""
time.sleep(0.2) # Wait longer than recovery timeout
"""Wait for recovery timeout.
Uses ``time._original_sleep`` (the un-patched sleep) because the
CircuitBreaker checks real wall-clock time to decide whether the
recovery window has elapsed. The global sleep cap installed by
``environment.py`` would reduce this to 10ms, preventing the 100ms
recovery timeout from expiring.
"""
_real_sleep = getattr(time, "_original_sleep", time.sleep)
_real_sleep(0.2) # Wait longer than recovery timeout (0.1s)
@then("the circuit breaker should enter half-open state")