From 91ac840ad207a924f03ff4cc7d938d0f5104a1b0 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Oct 2026 13:45:15 +0000 Subject: [PATCH] test(notifications): give the slow-target test room under parallel load It asserted a 2 s deadline ended the send within 5 s, which a loaded pytest -n auto run sometimes missed. Now the target would take 30 s, the deadline is 1 s and the read timeout 10 s, and the test checks the send ended between the deadline and half the target's time. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01PqBe9ycLaqFLZvCqL5wprK --- fastapi_backend/tests/api/test_notifications.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fastapi_backend/tests/api/test_notifications.py b/fastapi_backend/tests/api/test_notifications.py index d6349bf2b..b858493f8 100644 --- a/fastapi_backend/tests/api/test_notifications.py +++ b/fastapi_backend/tests/api/test_notifications.py @@ -302,17 +302,21 @@ def broken(*a, **k): def test_a_slow_target_is_cut_off(env): + """The deadline ends a send that a target drags out, long before the target would. The bounds are wide on + purpose: under a loaded parallel run threads get scheduled late, and only the order of magnitude matters.""" import socket srv = socket.socket() srv.bind(("127.0.0.1", 0)) srv.listen() + trickle_for = 30 # seconds the target would take to answer in full def trickle(): conn, _ = srv.accept() conn.recv(65536) conn.sendall(b"HTTP/1.1 200 OK\r\nContent-Length: 1000\r\n\r\n") - for _ in range(40): # a byte every quarter second: never quiet long enough for the read timeout + end = time.monotonic() + trickle_for + while time.monotonic() < end: # a byte every quarter second: never quiet long enough for the read timeout try: conn.sendall(b"x") except OSError: @@ -321,8 +325,10 @@ def trickle(): conn.close() threading.Thread(target=trickle, daemon=True).start() + url = f"http://127.0.0.1:{srv.getsockname()[1]}/" t0 = time.monotonic() with pytest.raises(TimeoutError): - notify.post(env["cfg"], f"http://127.0.0.1:{srv.getsockname()[1]}/", b"{}", {}, timeout=1, deadline=2) - assert time.monotonic() - t0 < 5 + notify.post(env["cfg"], url, b"{}", {}, timeout=10, deadline=1) + took = time.monotonic() - t0 + assert 1 <= took < trickle_for / 2, took srv.close()