Fix thread safety and test isolation in API tracking#297
Conversation
|
🚫 This pull request was requested to be canceled by Abhi Mehrotra (a GitHub user), so it was removed from the merge queue. See more details here.
|
- Add setUp/tearDown methods to save/restore counter state - Update tests to track increments relative to initial values - Align all statistics labels consistently (23 chars width) Co-authored-by: abhimehro <84992105+abhimehro@users.noreply.github.com>
|
👋 Development Partner is reviewing this PR. Will provide feedback shortly. |
There was a problem hiding this comment.
Pull request overview
Improves the reliability of API call tracking by addressing concurrent counter updates and making the associated tests independent, while also standardizing the summary output alignment for the new stats section.
Changes:
- Added synchronization around API tracking counters to avoid lost updates under concurrent execution.
- Updated API tracking tests to preserve/restore global counter state and assert relative increments for isolation.
- Adjusted API/Cache statistics printing to use consistent label padding and right-aligned numeric widths.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
main.py |
Aligns the API/Cache statistics summary output formatting (and includes the thread-safety changes described in the PR). |
tests/test_api_tracking.py |
Adds setUp/tearDown state restore and switches assertions to relative increments to prevent cross-test coupling. |
| print(f" • Errors (non-fatal): {_cache_stats['errors']:>7,}") | ||
|
|
||
| # Calculate cache effectiveness | ||
| total_requests = _cache_stats["hits"] + _cache_stats["misses"] + _cache_stats["validations"] |
There was a problem hiding this comment.
PR description says statistics output alignment/number formatting was standardized across cache statistics, but the Cache effectiveness line later in this same block still uses its previous spacing/width ({cache_effectiveness:>6.1f}%), so the numeric column won’t fully align with the :>7, counts above. Consider updating that line as well so the section is consistently aligned end-to-end.
0644cc4
into
perf/api-call-tracking-and-summary-590a8614ca343f92
Addresses review feedback from PR #270 identifying race conditions in concurrent counter updates and test isolation issues.
Changes
Thread Safety
_api_stats_lockto synchronize counter increments across_api_get,_api_post,_api_delete,_api_post_form_cache_lockfor blocklist fetch tracking in_gh_getTest Isolation
TestAPITrackingto save/restore counter state== 1) to relative increments (== initial + 1)Display Alignment
:>6,to:>7,for consistent right-alignmentAll 11 tests passing (5 API tracking, 6 cache optimization). CodeQL: 0 alerts.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.