mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-06 05:17:15 +00:00
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 sincec918d07b50(#51024, @ethernet8023, 2026-06-22); the _http_probe sleep sincefb51253620(#34188, @benbarclay, 2026-05-29).
This commit is contained in:
1 parent
800c634691
commit
d33d4fd9e7
3 files changed
+17
-2
No files matched your search
@@ -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
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user