test: update SSE tests to use StreamingASGITransport instead of uvicorn for server testing#1566
Open
bjoaquinc wants to merge 24 commits intomodelcontextprotocol:mainfrom
Open
test: update SSE tests to use StreamingASGITransport instead of uvicorn for server testing#1566bjoaquinc wants to merge 24 commits intomodelcontextprotocol:mainfrom
bjoaquinc wants to merge 24 commits intomodelcontextprotocol:mainfrom
Conversation
…st_context_propogation to apply this methodology
…nstead. DRY implementation
95d778a to
3d2fea9
Compare
Author
|
Done with all updates and ready for a review. |
9 tasks
Contributor
|
Related: #1728 (v2 test client improvements) |
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.
This implements fixes to the
StreamingASGITransportto properly handle SSE streaming and disconnect signaling. The key changes were:receive()to fix SSE hangingSseServerTransportto eliminate ResourceWarningshttp.response.startwith NoopASGItests/server/test_sse_security.pyandtests/shared/test_sse.pyto use transports instead of real servers with uvicornMotivation and Context
Partially resolves #857
How Has This Been Tested?
Since I updated the testing methodology I made sure to run the test in batches of 30 (to check for race conditions). Using the command:
passed=0; failed=0; for i in {1..30}; do echo "=== Run $i/30 ===" && uv run --resolution="$RESOLUTION" pytest "$FILE_PATH" -q && passed=$((passed+1)) || failed=$((failed+1)); done; echo "==== SUMMARY: $passed passed, $failed failed out of 30 runs ===="for the following resolutions and files:
tests/server/test_sse_security.pyforlowest-directandhighesttests/shared/test_sse.pyforlowest-directandhighestAll tests passed:
Breaking Changes
None.
StreamingASGITransportis only meant for testing. The only change I made toSseServerTransportwas to properly clean upsse_stream_readerwhich is best practice and doesn't break functionality. The modified tests all function as expected.Types of changes
Checklist
Additional context