Skip to content

Commit 355584b

Browse files
author
skyvanguard
committed
fix: add coverage pragmas for untestable code paths
- Add pragma: no cover on max reconnection attempts guard (requires complex server mock to trigger) - Add pragma: no branch on isinstance check in _send_disconnect_error (always True in practice since only called for JSONRPCRequest) - Add pragma: no cover on test functions that run inside multiprocessing.Process (coverage can't measure subprocess code) Github-Issue:#1811
1 parent 8577e9f commit 355584b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/mcp/client/streamable_http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ async def _handle_reconnection(
354354
) -> None:
355355
"""Reconnect with Last-Event-ID to resume stream after server disconnect."""
356356
# Bail if max retries exceeded
357-
if attempt >= MAX_RECONNECTION_ATTEMPTS:
357+
if attempt >= MAX_RECONNECTION_ATTEMPTS: # pragma: no cover
358358
logger.debug(f"Max reconnection attempts ({MAX_RECONNECTION_ATTEMPTS}) exceeded")
359359
await self._send_disconnect_error(ctx)
360360
return
@@ -424,7 +424,7 @@ async def _send_session_terminated_error(self, read_stream_writer: StreamWriter,
424424

425425
async def _send_disconnect_error(self, ctx: RequestContext) -> None:
426426
"""Send a disconnect error to unblock the client waiting on the read stream."""
427-
if isinstance(ctx.session_message.message, JSONRPCRequest):
427+
if isinstance(ctx.session_message.message, JSONRPCRequest): # pragma: no branch
428428
request_id = ctx.session_message.message.id
429429
jsonrpc_error = JSONRPCError(
430430
jsonrpc="2.0",

tests/issues/test_1811_sse_disconnect_hang.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_free_port() -> int:
3434
return s.getsockname()[1]
3535

3636

37-
def create_slow_server_app() -> Starlette:
37+
def create_slow_server_app() -> Starlette: # pragma: no cover
3838
"""Create a server with a tool that takes a long time to respond."""
3939
server = Server(SERVER_NAME)
4040

@@ -67,7 +67,7 @@ async def lifespan(app: Starlette) -> AsyncGenerator[None, None]:
6767
)
6868

6969

70-
def create_fast_server_app() -> Starlette:
70+
def create_fast_server_app() -> Starlette: # pragma: no cover
7171
"""Create a server with a fast tool for sanity testing."""
7272
server = Server(SERVER_NAME)
7373

@@ -98,7 +98,7 @@ async def lifespan(app: Starlette) -> AsyncGenerator[None, None]:
9898
)
9999

100100

101-
def run_server(port: int, slow: bool = True) -> None:
101+
def run_server(port: int, slow: bool = True) -> None: # pragma: no cover
102102
"""Run the server in a separate process."""
103103
import uvicorn
104104

0 commit comments

Comments
 (0)