ci: reduce Python test overhead and Windows latency (#6357)
* test: merge overlapping semantic contract coverage Consolidate the six confirmed NAN-310 overlap groups while preserving replay, usage, generation kwargs, archive metadata, inspect fields, and subagent crash/redelivery assertions. * test: lighten history seeds and layer runner progress rules * ci: defer test storage setup and record phase timings Close each listener-owned binary bridge before waiting for its TCP server; retain active upload and undecided-connection regressions. Avoid consuming readiness twice and run the repository import scan once in its static gate. NAN-310. * test: scope filesystem mocks and observe consumed socket prefixes * test: publish subprocess readiness files atomically * ci: isolate external tool discovery and use three Windows workers
This commit is contained in:
1 parent
743c51e81f
commit
f284749d2f
28 files changed
+518
-448
No files matched your search
@@ -25,8 +25,8 @@ class BinaryHTTPBridge:
|
||||
"""Own HTTP connections alongside a websockets ``serve`` instance.
|
||||
|
||||
Pass ``connection_factory`` as ``create_connection`` to serve/unix_serve.
|
||||
After closing the listening server, await ``shutdown`` before disposing the
|
||||
upload store. Request decompression is deliberately disabled: declared body
|
||||
After closing the listener, await ``shutdown`` before ``server.wait_closed``
|
||||
and disposing the upload store. Request decompression is deliberately disabled: declared body
|
||||
lengths must measure the exact bytes the upload store writes.
|
||||
"""
|
||||
|
||||
|
||||
@@ -646,9 +646,12 @@ class WebSocketChannel(BaseChannel):
|
||||
"WebSocket listener is no longer accepting connections"
|
||||
)
|
||||
|
||||
async def _close_server(self, server: Server, socket_path: str) -> None:
|
||||
async def _close_server(
|
||||
self, server: Server, socket_path: str, bridge: BinaryHTTPBridge,
|
||||
) -> None:
|
||||
server.close()
|
||||
try:
|
||||
await bridge.shutdown()
|
||||
await server.wait_closed()
|
||||
except OSError as exc:
|
||||
self.logger.warning("WebSocket server close failed: {}", exc)
|
||||
@@ -701,8 +704,6 @@ class WebSocketChannel(BaseChannel):
|
||||
async def handler(connection: ServerConnection) -> None:
|
||||
await self._connection_loop(connection)
|
||||
|
||||
bridge = BinaryHTTPBridge(self._uploads.handle)
|
||||
|
||||
async def prune_uploads() -> None:
|
||||
while not stop_event.is_set():
|
||||
self._uploads.store.prune()
|
||||
@@ -718,6 +719,7 @@ class WebSocketChannel(BaseChannel):
|
||||
failures = 0
|
||||
while not stop_event.is_set():
|
||||
server: Server | None = None
|
||||
bridge = BinaryHTTPBridge(self._uploads.handle)
|
||||
was_serving = False
|
||||
started_at = 0.0
|
||||
try:
|
||||
@@ -797,7 +799,9 @@ class WebSocketChannel(BaseChannel):
|
||||
finally:
|
||||
self._running = False
|
||||
if server is not None:
|
||||
await self._close_server(server, socket_path)
|
||||
await self._close_server(server, socket_path, bridge)
|
||||
else:
|
||||
await bridge.shutdown()
|
||||
if self._server is server:
|
||||
self._server = None
|
||||
|
||||
@@ -808,7 +812,6 @@ class WebSocketChannel(BaseChannel):
|
||||
finally:
|
||||
prune_task.cancel()
|
||||
await asyncio.gather(prune_task, return_exceptions=True)
|
||||
await bridge.shutdown()
|
||||
self._uploads.store.clear()
|
||||
self._running = False
|
||||
if self._server_task is task:
|
||||
|
||||
@@ -176,3 +176,30 @@ async def test_stalled_upload_reports_timeout_and_keeps_connection_retryable(gat
|
||||
assert not [p for p in channel.gateway.uploads.store.media_dir.rglob("*") if p.is_file()]
|
||||
async with http.post(http_url + capability["path"], data=b"xy", headers=headers) as response:
|
||||
assert response.status == 201
|
||||
|
||||
|
||||
async def test_stopping_listener_cancels_active_upload_before_clearing_store(gateway):
|
||||
channel, _, http_url, ws_url = gateway
|
||||
port = int(http_url.rsplit(":", 1)[1])
|
||||
async with connect(ws_url) as ws:
|
||||
capability = (await event(ws, "ready"))["upload"]
|
||||
reader, writer = await asyncio.open_connection("127.0.0.1", port)
|
||||
try:
|
||||
writer.write((
|
||||
f"POST {capability['path']} HTTP/1.1\r\nHost: localhost\r\n"
|
||||
f"Authorization: Bearer {capability['token']}\r\n"
|
||||
"Content-Type: image/png\r\nContent-Length: 1024\r\n"
|
||||
"Expect: 100-continue\r\n\r\n"
|
||||
).encode("ascii"))
|
||||
await writer.drain()
|
||||
assert b"100 Continue" in await asyncio.wait_for(reader.readuntil(b"\r\n\r\n"), 2)
|
||||
writer.write(b"partial")
|
||||
await writer.drain()
|
||||
async with asyncio.timeout(3):
|
||||
await channel.stop()
|
||||
await reader.read()
|
||||
await ws.wait_closed()
|
||||
assert not [p for p in channel.gateway.uploads.store.media_dir.rglob("*") if p.is_file()]
|
||||
finally:
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
@@ -60,8 +60,8 @@ async def test_binary_body_exceeds_ws_frame_limit_without_changing_ws(tmp_path):
|
||||
assert ws.close_code == 1009
|
||||
finally:
|
||||
server.close()
|
||||
await server.wait_closed()
|
||||
await bridge.shutdown()
|
||||
await server.wait_closed()
|
||||
store.clear()
|
||||
|
||||
|
||||
@@ -90,10 +90,12 @@ async def test_fragmented_method_and_shutdown_of_undecided_connection():
|
||||
idle_reader, idle_writer = await asyncio.open_connection("127.0.0.1", port)
|
||||
idle_writer.write(b"P")
|
||||
await idle_writer.drain()
|
||||
await asyncio.sleep(0.01)
|
||||
async with asyncio.timeout(2):
|
||||
while not any(connection._prefix == b"P" for connection in bridge.pending_connections):
|
||||
await asyncio.sleep(0)
|
||||
server.close()
|
||||
await server.wait_closed()
|
||||
await bridge.shutdown()
|
||||
await server.wait_closed()
|
||||
assert await asyncio.wait_for(idle_reader.read(), 2) == b""
|
||||
idle_writer.close()
|
||||
await idle_writer.wait_closed()
|
||||
@@ -101,8 +103,8 @@ async def test_fragmented_method_and_shutdown_of_undecided_connection():
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
server.close()
|
||||
await server.wait_closed()
|
||||
await bridge.shutdown()
|
||||
await server.wait_closed()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -136,8 +138,8 @@ async def test_ambiguous_http_framing_is_rejected_before_handler(headers):
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
server.close()
|
||||
await server.wait_closed()
|
||||
await bridge.shutdown()
|
||||
await server.wait_closed()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -165,8 +167,8 @@ async def test_request_body_is_not_automatically_decompressed():
|
||||
assert received == [body]
|
||||
finally:
|
||||
server.close()
|
||||
await server.wait_closed()
|
||||
await bridge.shutdown()
|
||||
await server.wait_closed()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -191,8 +193,8 @@ async def test_incomplete_http_headers_have_a_deadline(monkeypatch):
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
server.close()
|
||||
await server.wait_closed()
|
||||
await bridge.shutdown()
|
||||
await server.wait_closed()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -233,6 +235,6 @@ async def test_parsed_request_outlasts_header_deadline(tmp_path, monkeypatch):
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
server.close()
|
||||
await server.wait_closed()
|
||||
await bridge.shutdown()
|
||||
await server.wait_closed()
|
||||
store.clear()
|
||||
@@ -40,6 +40,7 @@ from nanobot.bus.outbound_events import (
|
||||
UserInputEvent,
|
||||
)
|
||||
from nanobot.bus.queue import MessageBus
|
||||
from nanobot.channels.websocket import runtime as websocket_runtime
|
||||
from nanobot.channels.websocket.runtime import (
|
||||
WebSocketChannel,
|
||||
WebSocketConfig,
|
||||
@@ -212,6 +213,44 @@ async def start_listener():
|
||||
await asyncio.gather(task, return_exceptions=True)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_shutdown_closes_undecided_connections_before_waiting_for_server(
|
||||
bus, start_listener, monkeypatch,
|
||||
) -> None:
|
||||
bridges = []
|
||||
bridge_type = websocket_runtime.BinaryHTTPBridge
|
||||
|
||||
def create_bridge(handler):
|
||||
bridge = bridge_type(handler)
|
||||
bridges.append(bridge)
|
||||
return bridge
|
||||
|
||||
monkeypatch.setattr(websocket_runtime, "BinaryHTTPBridge", create_bridge)
|
||||
channel = _ch(bus)
|
||||
port, start_task = await start_listener(channel)
|
||||
async with websockets.connect(f"ws://127.0.0.1:{port}/ws") as client:
|
||||
assert json.loads(await client.recv())["event"] == "ready"
|
||||
reader, writer = await asyncio.open_connection("127.0.0.1", port)
|
||||
try:
|
||||
writer.write(b"P")
|
||||
await writer.drain()
|
||||
async with asyncio.timeout(2):
|
||||
while not any(
|
||||
connection._prefix == b"P" for connection in bridges[0].pending_connections
|
||||
):
|
||||
await asyncio.sleep(0)
|
||||
async with asyncio.timeout(2):
|
||||
await channel.stop()
|
||||
await start_task
|
||||
assert await reader.read() == b""
|
||||
await client.wait_closed()
|
||||
assert not bridges[0].pending_connections
|
||||
assert channel._server is None
|
||||
finally:
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
|
||||
|
||||
async def _wait_for_connection_cleanup(
|
||||
channel: WebSocketChannel,
|
||||
connection: Any,
|
||||
|
||||
Reference in new issue
Block a user