fix: Replace remaining manual server polling with wait_for_server helper (#1529)
This commit is contained in:
parent
c44e68f766
commit
db9e451551
4 changed files with 12 additions and 61 deletions
|
|
@ -7,13 +7,13 @@ Verifies that Unicode text is correctly transmitted and received in both directi
|
||||||
|
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import socket
|
import socket
|
||||||
import time
|
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from mcp.client.session import ClientSession
|
from mcp.client.session import ClientSession
|
||||||
from mcp.client.streamable_http import streamablehttp_client
|
from mcp.client.streamable_http import streamablehttp_client
|
||||||
|
from tests.test_helpers import wait_for_server
|
||||||
|
|
||||||
# Test constants with various Unicode characters
|
# Test constants with various Unicode characters
|
||||||
UNICODE_TEST_STRINGS = {
|
UNICODE_TEST_STRINGS = {
|
||||||
|
|
@ -158,19 +158,8 @@ def running_unicode_server(unicode_server_port: int) -> Generator[str, None, Non
|
||||||
proc = multiprocessing.Process(target=run_unicode_server, kwargs={"port": unicode_server_port}, daemon=True)
|
proc = multiprocessing.Process(target=run_unicode_server, kwargs={"port": unicode_server_port}, daemon=True)
|
||||||
proc.start()
|
proc.start()
|
||||||
|
|
||||||
# Wait for server to be running
|
# Wait for server to be ready
|
||||||
max_attempts = 20
|
wait_for_server(unicode_server_port)
|
||||||
attempt = 0
|
|
||||||
while attempt < max_attempts:
|
|
||||||
try:
|
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
||||||
s.connect(("127.0.0.1", unicode_server_port))
|
|
||||||
break
|
|
||||||
except ConnectionRefusedError:
|
|
||||||
time.sleep(0.1)
|
|
||||||
attempt += 1
|
|
||||||
else:
|
|
||||||
raise RuntimeError(f"Server failed to start after {max_attempts} attempts")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield f"http://127.0.0.1:{unicode_server_port}"
|
yield f"http://127.0.0.1:{unicode_server_port}"
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ that don't follow SDK conventions.
|
||||||
import json
|
import json
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import socket
|
import socket
|
||||||
import time
|
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
@ -22,6 +21,7 @@ from mcp import ClientSession, types
|
||||||
from mcp.client.streamable_http import streamablehttp_client
|
from mcp.client.streamable_http import streamablehttp_client
|
||||||
from mcp.shared.session import RequestResponder
|
from mcp.shared.session import RequestResponder
|
||||||
from mcp.types import ClientNotification, RootsListChangedNotification
|
from mcp.types import ClientNotification, RootsListChangedNotification
|
||||||
|
from tests.test_helpers import wait_for_server
|
||||||
|
|
||||||
|
|
||||||
def create_non_sdk_server_app() -> Starlette:
|
def create_non_sdk_server_app() -> Starlette:
|
||||||
|
|
@ -95,14 +95,9 @@ def non_sdk_server(non_sdk_server_port: int) -> Generator[None, None, None]:
|
||||||
proc.start()
|
proc.start()
|
||||||
|
|
||||||
# Wait for server to be ready
|
# Wait for server to be ready
|
||||||
start_time = time.time()
|
try:
|
||||||
while time.time() - start_time < 10:
|
wait_for_server(non_sdk_server_port, timeout=10.0)
|
||||||
try:
|
except TimeoutError:
|
||||||
with socket.create_connection(("127.0.0.1", non_sdk_server_port), timeout=0.1):
|
|
||||||
break
|
|
||||||
except (TimeoutError, ConnectionRefusedError):
|
|
||||||
time.sleep(0.1)
|
|
||||||
else:
|
|
||||||
proc.kill()
|
proc.kill()
|
||||||
proc.join(timeout=2)
|
proc.join(timeout=2)
|
||||||
pytest.fail("Server failed to start within 10 seconds")
|
pytest.fail("Server failed to start within 10 seconds")
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ single-feature servers across different transports (SSE and StreamableHTTP).
|
||||||
import json
|
import json
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import socket
|
import socket
|
||||||
import time
|
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
@ -60,6 +59,7 @@ from mcp.types import (
|
||||||
TextResourceContents,
|
TextResourceContents,
|
||||||
ToolListChangedNotification,
|
ToolListChangedNotification,
|
||||||
)
|
)
|
||||||
|
from tests.test_helpers import wait_for_server
|
||||||
|
|
||||||
|
|
||||||
class NotificationCollector:
|
class NotificationCollector:
|
||||||
|
|
@ -160,19 +160,8 @@ def server_transport(request: pytest.FixtureRequest, server_port: int) -> Genera
|
||||||
)
|
)
|
||||||
proc.start()
|
proc.start()
|
||||||
|
|
||||||
# Wait for server to be running
|
# Wait for server to be ready
|
||||||
max_attempts = 20
|
wait_for_server(server_port)
|
||||||
attempt = 0
|
|
||||||
while attempt < max_attempts:
|
|
||||||
try:
|
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
||||||
s.connect(("127.0.0.1", server_port))
|
|
||||||
break
|
|
||||||
except ConnectionRefusedError:
|
|
||||||
time.sleep(0.1)
|
|
||||||
attempt += 1
|
|
||||||
else:
|
|
||||||
raise RuntimeError(f"Server failed to start after {max_attempts} attempts")
|
|
||||||
|
|
||||||
yield transport
|
yield transport
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -252,19 +252,8 @@ def mounted_server(server_port: int) -> Generator[None, None, None]:
|
||||||
proc.start()
|
proc.start()
|
||||||
|
|
||||||
# Wait for server to be running
|
# Wait for server to be running
|
||||||
max_attempts = 20
|
|
||||||
attempt = 0
|
|
||||||
print("waiting for server to start")
|
print("waiting for server to start")
|
||||||
while attempt < max_attempts:
|
wait_for_server(server_port)
|
||||||
try:
|
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
||||||
s.connect(("127.0.0.1", server_port))
|
|
||||||
break
|
|
||||||
except ConnectionRefusedError:
|
|
||||||
time.sleep(0.1)
|
|
||||||
attempt += 1
|
|
||||||
else:
|
|
||||||
raise RuntimeError(f"Server failed to start after {max_attempts} attempts")
|
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
@ -367,19 +356,8 @@ def context_server(server_port: int) -> Generator[None, None, None]:
|
||||||
proc.start()
|
proc.start()
|
||||||
|
|
||||||
# Wait for server to be running
|
# Wait for server to be running
|
||||||
max_attempts = 20
|
|
||||||
attempt = 0
|
|
||||||
print("waiting for context server to start")
|
print("waiting for context server to start")
|
||||||
while attempt < max_attempts:
|
wait_for_server(server_port)
|
||||||
try:
|
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
||||||
s.connect(("127.0.0.1", server_port))
|
|
||||||
break
|
|
||||||
except ConnectionRefusedError:
|
|
||||||
time.sleep(0.1)
|
|
||||||
attempt += 1
|
|
||||||
else:
|
|
||||||
raise RuntimeError(f"Context server failed to start after {max_attempts} attempts")
|
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue