Skip to content

Conversation

jlowin
Copy link
Owner

@jlowin jlowin commented Oct 5, 2025

This pull request migrates the test infrastructure from asyncio to anyio, modernizing the async concurrency model and improving test speed, determinism, and reliability.

Presently, many tests (including almost all for remote MCP transports) run in subprocesses. This is time-consuming, resource-intensive, and makes debugging extremely difficult when errors surface in the subprocess instead of in the client.

This PR refactors all subprocess tests to instead run in anyio task groups, which has dramatic performance benefits (cutting local test time roughly in half) as well as resulting in sane tracebacks and debugging on the servers. Generally speaking, run_server_async replaces run_server_in_process in the test suite.

Apart from adjusting asyncio.Lock to anyio.Lock, this PR is almost entirely confined to the test suite.

@marvin-context-protocol marvin-context-protocol bot added enhancement Improvement to existing functionality. For issues and smaller PR improvements. tests labels Oct 5, 2025
@strawgate
Copy link
Collaborator

Do we actually need to use anyio for this? When I did this in my projects, removing asyncio_default_fixture_loop_scope = "session" and asyncio_default_test_loop_scope = "session" was enough to be able to create, yield, and connect to running servers.

Anyway, looks great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement to existing functionality. For issues and smaller PR improvements. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants