Skip to content

Commit fe72545

Browse files
committed
test: replace multiprocessing with threading for server test coverage
Replace multiprocessing.Process with threading.Thread + uvicorn.Server for test server fixtures (basic_server, json_server, resumable_server) so coverage.py can track server-side code in the same process. Changes: - Add _start_server_thread() helper using uvicorn.Server in a daemon thread - Graceful shutdown via server.should_exit instead of proc.kill() - Remove 8 pragma: no cover from test fixtures (no longer needed) - Add 8 new tests covering previously-uncovered branches - Remove dead run_server() function and unused http_client fixture - Convert pragma: no cover to pragma: lax no cover in source files for non-deterministic coverage lines (thread timing dependent) - Add pragma: no branch for partial branch coverage on guard lines
1 parent 7ba4fb8 commit fe72545

File tree

4 files changed

+309
-152
lines changed

4 files changed

+309
-152
lines changed

src/mcp/server/session.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ async def _received_notification(self, notification: types.ClientNotification) -
200200
case types.InitializedNotification():
201201
self._initialization_state = InitializationState.Initialized
202202
case _:
203-
if self._initialization_state != InitializationState.Initialized: # pragma: no cover
203+
if self._initialization_state != InitializationState.Initialized: # pragma: lax no cover
204204
raise RuntimeError("Received notification before initialization was complete")
205205

206206
async def send_log_message(
@@ -222,7 +222,7 @@ async def send_log_message(
222222
related_request_id,
223223
)
224224

225-
async def send_resource_updated(self, uri: str | AnyUrl) -> None: # pragma: no cover
225+
async def send_resource_updated(self, uri: str | AnyUrl) -> None:
226226
"""Send a resource updated notification."""
227227
await self.send_notification(
228228
types.ResourceUpdatedNotification(
@@ -446,7 +446,7 @@ async def elicit_url(
446446
metadata=ServerMessageMetadata(related_request_id=related_request_id),
447447
)
448448

449-
async def send_ping(self) -> types.EmptyResult: # pragma: no cover
449+
async def send_ping(self) -> types.EmptyResult: # pragma: lax no cover
450450
"""Send a ping request."""
451451
return await self.send_request(
452452
types.PingRequest(),
@@ -478,11 +478,11 @@ async def send_resource_list_changed(self) -> None:
478478
"""Send a resource list changed notification."""
479479
await self.send_notification(types.ResourceListChangedNotification())
480480

481-
async def send_tool_list_changed(self) -> None: # pragma: no cover
481+
async def send_tool_list_changed(self) -> None: # pragma: lax no cover
482482
"""Send a tool list changed notification."""
483483
await self.send_notification(types.ToolListChangedNotification())
484484

485-
async def send_prompt_list_changed(self) -> None: # pragma: no cover
485+
async def send_prompt_list_changed(self) -> None: # pragma: lax no cover
486486
"""Send a prompt list changed notification."""
487487
await self.send_notification(types.PromptListChangedNotification())
488488

0 commit comments

Comments
 (0)