Skip to content

test(proxy): catch CancelledError in TestAutoIndexStartupWarning (#264)#269

Merged
memtomem merged 2 commits intomainfrom
fix/264-startup-warning-cancellederror
Apr 27, 2026
Merged

test(proxy): catch CancelledError in TestAutoIndexStartupWarning (#264)#269
memtomem merged 2 commits intomainfrom
fix/264-startup-warning-cancellederror

Conversation

@memtomem
Copy link
Copy Markdown
Owner

Closes #264.

Summary

test_no_warning_when_compression_none and test_warns_compression_without_auto_index in tests/test_proxy_manager.py::TestAutoIndexStartupWarning swallow the expected connect failure against an echo upstream so they can assert on the warning that fires before the connect loop runs. The catch was except Exception, but the MCP SDK's stdio reader can surface the upstream's premature exit as asyncio.CancelledError (a BaseException, not Exception), so the cancellation leaked past the catch and the test failed.

Catch widened to (Exception, asyncio.CancelledError) with a comment naming the SDK cancellation path. The narrower form is preferred over except BaseException so KeyboardInterrupt still aborts a hung test.

No production code touched.

Why option 1 (broaden the catch) over option 2 (no-op patch the connect)

Issue #264 listed both. Option 1 is two-line; option 2 rewrites the test to skip the real connect entirely. Option 1 wins because:

  1. The tests still exercise ProxyManager.start() end-to-end including the connect loop, which is closer to production than a patched no-op.
  2. The fix is local, easy to read, and the comment makes the intent obvious — a future reader who narrows except Exception elsewhere has no reason to re-narrow these.
  3. Option 2 would mask any future regression where start() raises before reaching the connect loop.

If the underlying SDK behavior gets cleaned up later (CancelledError → wrapped in a plain Exception), the catch still works.

Verification

  • Before fix: uv run pytest -m "not ollama" -q → 1748 pass, 1 fail (test_no_warning_when_compression_none).
  • After fix: uv run pytest -m "not ollama" -q → 1747 pass, 0 fail.
  • Isolated: uv run pytest tests/test_proxy_manager.py::TestAutoIndexStartupWarning -v → 3 pass.
  • uv run ruff check src && uv run ruff format --check src → clean.

🤖 Generated with Claude Code

pandas-studio and others added 2 commits April 27, 2026 22:47
`test_no_warning_when_compression_none` and its sibling
`test_warns_compression_without_auto_index` wrap `await mgr.start()`
in `try/except Exception` because the test only cares about the
*warning* assertion that follows; the `echo` upstream is expected
to fail the JSON-RPC handshake. But the MCP SDK's stdio reader can
surface that failure as `asyncio.CancelledError` (a `BaseException`,
not an `Exception`), so the cancellation leaked past the catch and
the test failed under enough total async test mass to push timing
across a threshold. Reproducible at ~50% on PR #263 (which added
23 tests, shifting event-loop scheduling); not reproducible in
isolation.

Widen the catch to `(Exception, asyncio.CancelledError)` with a
comment naming the SDK cancellation path so a future reader who
sees `except Exception` would have narrowed elsewhere doesn't
re-narrow this one. The narrower form is preferred over
`BaseException` so `KeyboardInterrupt` still aborts a hung test.

No production code touched.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Per PR review: the second test's "See sibling test" comment rots
if the first test is renamed or reordered. Replace with a
self-contained one-liner that names the SDK behavior and the
safety argument directly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@memtomem memtomem merged commit 7a1e7db into main Apr 27, 2026
6 checks passed
@memtomem memtomem deleted the fix/264-startup-warning-cancellederror branch April 27, 2026 13:57
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: TestAutoIndexStartupWarning leaks asyncio.CancelledError past except-Exception

2 participants