Skip to content

TEST: Fix SQLite lock tests - #3121

Open
Roman Lutz (romanlutz) wants to merge 1 commit into
microsoft:mainfrom
romanlutz:romanlutz-sqlite-analytics-reliability
Open

Roman Lutz (romanlutz) wants to merge 1 commit into
microsoft:mainfrom
romanlutz:romanlutz-sqlite-analytics-reliability

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

Description

SQLite analytics lock tests can fail under loaded CI even when deadline handling is correct. The deadline test measured total wall time, including scheduling and cleanup, while cancellation tests used a one-second completion wait that could inject another cancellation. One cancellation budget also started before writer setup.

  • Replace the wall-clock assertion with an actual SQLITE_BUSY event and a controlled, test-only request clock. Reuse the isolated file-memory fixture and cover report, matrix, compact report, results, and facets.
  • Start cancellation budgets after writer setup and use the existing non-cancelling completion helper. Preserve the original task-cancellation message and repeated-cancellation coverage.
  • Check the exact reader connection's temporary and restored busy timeout, unchanged writer settings, and subsequent successful reads. Release writers and drain tasks before patches and fixtures close.

This is test-only. Production retry semantics from #3065, schema, shared helpers, and CI gates are unchanged. The semantic-report tests retain their 20/30-second absolute budgets. Their historical macOS timeouts remain unresolved; this PR does not claim to fix them.

Tests and Documentation

Verified on Windows/Python 3.14.4 with default development dependencies.

Affected modules: 193 passed.

uv run --no-sync --offline python -m pytest tests\unit\memory\test_attack_analytics.py tests\unit\memory\test_attack_analytics_lock_retry.py tests\unit\memory\test_attack_analytics_metadata.py tests\unit\memory\test_attack_analytics_eval_identity.py -n 4 --dist=loadfile -q --durations=12

Repeated synchronization checks: five runs passed, 22 tests each, 110 total.

Exact repeated command
foreach ($iteration in 1..5) { Write-Output "SQLite reliability repetition $iteration/5"; uv run --no-sync --offline python -m pytest tests\unit\memory\test_attack_analytics_lock_retry.py::test_sqlite_deadline_bounds_file_database_lock_wait_and_restores_timeout_async tests\unit\memory\test_attack_analytics_lock_retry.py::test_sqlite_read_succeeds_when_writer_releases_lock_async tests\unit\memory\test_attack_analytics_lock_retry.py::test_sqlite_lock_retry_cancellation_restores_connection_async tests\unit\memory\test_attack_analytics_lock_retry.py::test_sqlite_timeout_restoration_finishes_under_repeated_cancellation_async -n 4 --dist=load -q --tb=short; if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } }

Type checks and applicable hooks: passed. The hooks include Ruff checks and formatting; commit-time hooks passed again without bypasses.

uv run --no-sync --offline ty check tests\unit\memory\test_attack_analytics.py tests\unit\memory\test_attack_analytics_lock_retry.py
uv run --no-sync --offline pre-commit run --files tests\unit\memory\test_attack_analytics.py tests\unit\memory\test_attack_analytics_lock_retry.py --show-diff-on-failure

Private fault-injection replays reproduced the original failures: delayed restoration caused three wall-clock assertion failures and two completion-timeout failures; simulated slow writer setup caused two premature-expiry failures. After the changes, those scenarios passed all 20 projection variants and all 10 cancellation variants, respectively. The instrumentation is not part of this changeset.

Documentation and JupyText: N/A for this test-only change. macOS and full-suite CI reproduction were not performed.

Drive lock deadline expiry from observed SQLITE_BUSY and a controlled request clock. Reuse isolated file memory, verify the exact reader connection's settings, arm cancellation budgets after writer setup, and observe completion without injecting cancellation. Preserve production retry semantics and semantic-report budgets.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
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