From ac35246c6a6cb8d33edb62234e1359e054b7325d Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Wed, 18 Nov 2026 20:52:49 -0800 Subject: [PATCH 1/2] test(computers): the site proxy tests wait for the connections they read to be logged Three tests slept a fixed 0.3 s for the forward port's connection records, which it writes as each connection ends; the slow host's record waits out the 0.3 s upstream timeout itself, so on a loaded runner the log was read before it was written. They now wait until the records they check are there, for up to 10 s. Co-Authored-By: Claude Opus 5.5 --- tst/unit/env/envs/test_computer_site_proxy.py | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tst/unit/env/envs/test_computer_site_proxy.py b/tst/unit/env/envs/test_computer_site_proxy.py index 3e8aabb5b..dd9a59304 100644 --- a/tst/unit/env/envs/test_computer_site_proxy.py +++ b/tst/unit/env/envs/test_computer_site_proxy.py @@ -104,6 +104,17 @@ async def _forward_port(config, network=None): server.close() +async def _until_logged(capsys, count: int) -> str: + """What the proxy has written to stderr once it holds ``count`` records: each connection is logged as it ends, so a + test waits for the records rather than for a fixed time a loaded runner can outlast.""" + log = "" + async with asyncio.timeout(10): + while len(_logged(log)) < count: + await asyncio.sleep(0.02) + log += capsys.readouterr().err + return log + + async def _exchange(port, request: bytes, *, server_hostname=None, cadata=None, reader_writer=None): if reader_writer is None: context = None @@ -447,14 +458,14 @@ async def test_the_forward_port_tunnels_a_live_sites_host_straight_to_it_and_sen plain = await _exchange(port, b"GET http://github.com/a?b=1 HTTP/1.1\r\nHost: github.com\r\n" b"Proxy-Connection: keep-alive\r\n\r\n") plain[3][1].close() - await asyncio.sleep(0.3) # each connection is logged as it ends + log = await _until_logged(capsys, 2) assert established.startswith(b"HTTP/1.1 200 ") and opened == [("github.githubassets.com", 8443), ("github.com", 80)] assert (tunnelled[0], tunnelled[2], plain[0], plain[2]) == ("HTTP/1.1 200 OK", b"hello", "HTTP/1.1 200 OK", b"hello") assert [request[0] for request in live.requests] == ["GET /x HTTP/1.1", "GET /a?b=1 HTTP/1.1"] assert live.requests[1][1]["connection"] == "close" and "proxy-connection" not in live.requests[1][1] assert live.requests[1][1]["host"] == "github.com" and upstream.requests == [] - logged = _logged(capsys.readouterr().err, "connection") + logged = _logged(log + capsys.readouterr().err, "connection") assert [(entry["host"], entry["port"], entry["address"]) for entry in logged] == [ ("github.githubassets.com", 8443, "127.0.0.1"), ("github.com", 80, "127.0.0.1")] assert all(entry["bytes_sent"] > 0 and entry["bytes_received"] > 0 and entry["duration_s"] >= 0 for entry in logged) @@ -507,12 +518,12 @@ async def resolve(host, port): private = await _exchange(port, b"GET http://intranet.example/b HTTP/1.1\r\n" b"Host: intranet.example\r\n\r\n") private[3][1].close() - await asyncio.sleep(0.3) # each connection is logged as it ends + log = await _until_logged(capsys, 2) assert (public[0], public[2], private[0], private[2]) == ("HTTP/1.1 200 OK", b"hello", "HTTP/1.1 200 OK", b"hello") assert [head.split(b"\r\n")[0] for head in egress.heads] == [b"CONNECT github.com:80 HTTP/1.1"] assert opened == [("intranet.example", 80)] and [request[0] for request in live.requests] == ["GET /b HTTP/1.1"] - logged = _logged(capsys.readouterr().err, "connection") + logged = _logged(log + capsys.readouterr().err, "connection") # Through the egress proxy a connection names the proxy, which decides which of the site's addresses it dials. assert [(entry["host"], entry["address"], entry.get("via")) for entry in logged] == [ ("github.com", "127.0.0.1", "egress"), ("intranet.example", "127.0.0.1", None)] @@ -595,8 +606,8 @@ async def open_connection(host, port, **kwargs): for request in requests: answer = await _exchange(port, request) answer[3][1].close() - await asyncio.sleep(0.3) # each connection is logged as it ends - shared_log = capsys.readouterr().err + log = await _until_logged(capsys, 3) + shared_log = log + capsys.readouterr().err def shape(log: str) -> list: return [(kind, sorted(record), record.get("reason")) for entry in _logged(log) for kind, record in entry.items()] From e373a4014c30a34279993d4936ec9c9ace1733f1 Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Wed, 18 Nov 2026 21:17:41 -0800 Subject: [PATCH 2/2] test(computers): name the site proxy tests' log wait and poll interval Co-Authored-By: Claude Opus 5.5 --- tst/unit/env/envs/test_computer_site_proxy.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tst/unit/env/envs/test_computer_site_proxy.py b/tst/unit/env/envs/test_computer_site_proxy.py index dd9a59304..7b5284bef 100644 --- a/tst/unit/env/envs/test_computer_site_proxy.py +++ b/tst/unit/env/envs/test_computer_site_proxy.py @@ -104,13 +104,18 @@ async def _forward_port(config, network=None): server.close() +# How long a test waits for the proxy to log the connections it checks, and how often it looks. +LOG_WAIT_S = 10.0 +LOG_POLL_S = 0.02 + + async def _until_logged(capsys, count: int) -> str: """What the proxy has written to stderr once it holds ``count`` records: each connection is logged as it ends, so a test waits for the records rather than for a fixed time a loaded runner can outlast.""" log = "" - async with asyncio.timeout(10): + async with asyncio.timeout(LOG_WAIT_S): while len(_logged(log)) < count: - await asyncio.sleep(0.02) + await asyncio.sleep(LOG_POLL_S) log += capsys.readouterr().err return log