test: cover performance audit findings before fixing them - #46
Merged
Merged
Conversation
Behavioural tests for every code-level finding of the performance audit. Known defects are documented as xfail(strict=True) tests, so they fail loudly once fixed and the marker gets removed with the fix. - add PatternLocMemCache + locmem_cache fixture: a real in-memory cache with delete_pattern, as DummyCache never stores and lacks delete_pattern - replace tests mocking delete_pattern with cache-hit based assertions - cover cache invalidation cost and scope, N+1 queries, oversized JSON loads, stampedes, throttling, auth overhead, snapshot lost update, stale gamedata caches and per-user Cache-Control Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Coverage variation | ✅ +0.12% coverage variation (-1.00%) |
| Diff coverage | ✅ ∅ diff coverage |
Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (8de36d9) 3116 2808 90.12% Head commit (11e4b9e) 3278 (+162) 2958 (+150) 90.24% (+0.12%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>
Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#46) 0 0 ∅ (not applicable) Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
The test enqueued the real Celery task, which needs a reachable broker and failed in CI with its placeholder broker URL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test-only PR (no application code changes) that pins down every code-level finding of the backend performance audit before any fix lands.
xfail(strict=True)tests with anaudit:reason. CI stays green; once a fix lands the test XPASSes, which fails the run until the marker is removed together with the fix. All 40 were verified to fail on their own assertion via--runxfail.PatternLocMemCache+locmem_cachefixture (backend/tests/cache_backends.py,conftest.py). The testDummyCachenever stores and has nodelete_pattern, so cache/invalidation bugs were invisible; the old tests only passed by mockingdelete_pattern.delete_patternwas called with an exact pattern now assert on actual cache hits/misses and response data.Coverage by finding
1vs11over-match, passing guards for all correct invalidation pathsempire_stateloaded in 3 views, CX list/retrieve N+1, shared-view N+1, repeatedcx_datapre_savedouble readCache-Control: public, stale planet/building caches, api key in task args, insighttickerbugNew defects surfaced
sync_stateruns two keyspace scans, althoughempire_stateis in no cached payload.Notes for the fixes
planet_search;planets/multipleaccepts at most 100 ids.cx_datanesting in the plan list, owner empires on the public shared view, removing Basic auth, gzip (drop if the proxy compresses).DEBUGdefault (deployment config); SSE (no pytest-asyncio).test_planning_signals.py,test_user_signals.py): the test tree has no__init__.py, so duplicate basenames collide.Test plan
uv run pytest: 243 passed, 40 xfaileduv run pytest --runxfail: exactly the 40 xfails failuv run ruff check/uv run ruff format --checkuv run ty check --exclude "**/migrations/*.py"🤖 Generated with Claude Code