From d33d4fd9e7b57e16316ca953523bba596e4f6d5e Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Sat, 31 Oct 2026 14:55:06 +0530 Subject: [PATCH] test(docker): the pause between failed probes stops at the poll deadline poll_container and the dashboard _http_probe slept a full interval after every failed probe, even when less time than that was left, so a poll could run up to one interval past the deadline its caller gave. Clamp the sleep to the time remaining. The overrun never turned a failure into a pass; it only made the deadline inexact. Pre-existing: the poll_container sleep since c918d07b50 (#51024, @ethernet8023, 2026-06-22); the _http_probe sleep since fb51253620 (#34188, @benbarclay, 2026-05-29). --- tests/docker/conftest.py | 2 +- tests/docker/test_dashboard.py | 2 +- tests/test_docker_poll_stalled_exec.py | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/docker/conftest.py b/tests/docker/conftest.py index b6aebd32de..646930e12b 100644 --- a/tests/docker/conftest.py +++ b/tests/docker/conftest.py @@ -257,7 +257,7 @@ def poll_container( last = r.stdout if r.returncode == 0: return True, last - time.sleep(interval_s) + time.sleep(min(interval_s, max(0.0, end - time.monotonic()))) if not completed: raise AssertionError(f"No probe of {container} completed within {deadline_s}s; {last}") return False, last diff --git a/tests/docker/test_dashboard.py b/tests/docker/test_dashboard.py index 91b7a78a80..3c6003305a 100644 --- a/tests/docker/test_dashboard.py +++ b/tests/docker/test_dashboard.py @@ -113,7 +113,7 @@ except urllib.error.HTTPError as h: last_err = f"parse: {exc!r} / stdout={r.stdout!r}" else: last_err = f"rc={r.returncode} stderr={r.stderr!r}" - time.sleep(0.5) + time.sleep(min(0.5, max(0.0, end - time.monotonic()))) raise AssertionError( f"Probe of {path} never returned HTTP within {deadline_s}s; " f"last error: {last_err}" diff --git a/tests/test_docker_poll_stalled_exec.py b/tests/test_docker_poll_stalled_exec.py index 9261052d2f..7795c44f2b 100644 --- a/tests/test_docker_poll_stalled_exec.py +++ b/tests/test_docker_poll_stalled_exec.py @@ -104,3 +104,18 @@ def test_stall_after_a_completed_probe_keeps_its_output(monkeypatch): failed = SimpleNamespace(returncode=1, stdout="HOME=/root", stderr="") monkeypatch.setattr(docker_conftest, "docker_exec_sh", _scripted_exec(clock, [failed, "stall"])) assert docker_conftest.poll_container("c", "probe", deadline_s=12.0) == (False, "HOME=/root") + + +@pytest.mark.parametrize("module", [docker_conftest, test_dashboard], ids=["poll_container", "_http_probe"]) +def test_sleep_between_failed_probes_stops_at_the_deadline(monkeypatch, module): + """The pause after a failed probe never runs past the deadline the caller gave.""" + clock = _Clock() + monkeypatch.setattr(module, "time", clock) + failed = SimpleNamespace(returncode=1, stdout="", stderr="") + monkeypatch.setattr(module, "docker_exec_sh", _scripted_exec(clock, [failed])) + if module is docker_conftest: + assert module.poll_container("c", "probe", deadline_s=1.0) == (False, "") + else: + with pytest.raises(AssertionError, match="never returned HTTP"): + module._http_probe("c", "/api/status", deadline_s=1.0) + assert clock.now <= 1.0