Skip to content

Commit 9c0d31f

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 9c0d31f

File tree

4 files changed

+334
-173
lines changed

4 files changed

+334
-173
lines changed

src/mcp/server/session.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,10 @@ 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
204-
raise RuntimeError("Received notification before initialization was complete")
203+
if self._initialization_state != InitializationState.Initialized:
204+
raise RuntimeError(
205+
"Received notification before initialization was complete"
206+
) # pragma: lax no cover
205207

206208
async def send_log_message(
207209
self,
@@ -222,7 +224,7 @@ async def send_log_message(
222224
related_request_id,
223225
)
224226

225-
async def send_resource_updated(self, uri: str | AnyUrl) -> None: # pragma: no cover
227+
async def send_resource_updated(self, uri: str | AnyUrl) -> None:
226228
"""Send a resource updated notification."""
227229
await self.send_notification(
228230
types.ResourceUpdatedNotification(
@@ -446,9 +448,9 @@ async def elicit_url(
446448
metadata=ServerMessageMetadata(related_request_id=related_request_id),
447449
)
448450

449-
async def send_ping(self) -> types.EmptyResult: # pragma: no cover
451+
async def send_ping(self) -> types.EmptyResult:
450452
"""Send a ping request."""
451-
return await self.send_request(
453+
return await self.send_request( # pragma: lax no cover
452454
types.PingRequest(),
453455
types.EmptyResult,
454456
)
@@ -478,13 +480,13 @@ async def send_resource_list_changed(self) -> None:
478480
"""Send a resource list changed notification."""
479481
await self.send_notification(types.ResourceListChangedNotification())
480482

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

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

489491
async def send_elicit_complete(
490492
self,

0 commit comments

Comments
 (0)