Skip to content

The agent that grows with you

test(cron): stabilize heartbeat grace assertion

KoNit-Kea92bbc5c252
diff --git a/tests/cron/test_script_claim_heartbeat.py b/tests/cron/test_script_claim_heartbeat.py
index 1903b78fff4..1b6d7f74d70 100644
--- a/tests/cron/test_script_claim_heartbeat.py
+++ b/tests/cron/test_script_claim_heartbeat.py
@@ -647,17 +647,21 @@ def test_repeated_heartbeat_errors_cancel_after_bounded_grace(monkeypatch):
import cron.scheduler as scheduler
from cron import scheduler_script as sched_script
+ last_confirmed_at = []
+ cancellation_after = []
calls = 0
def heartbeat(*_args, **_kwargs):
nonlocal calls
calls += 1
if calls == 1:
+ last_confirmed_at.append(time.monotonic())
return True
raise OSError("store unavailable")
def run_body(_job, **kwargs):
assert kwargs["fire_claim_lost"].wait(timeout=0.5)
+ cancellation_after.append(time.monotonic() - last_confirmed_at[0])
return True
job = {
@@ -670,7 +674,7 @@ def test_repeated_heartbeat_errors_cancel_after_bounded_grace(monkeypatch):
monkeypatch.setattr(scheduler, "_FIRE_CLAIM_HEARTBEAT_GRACE_SECONDS", 0.03)
assert scheduler.run_one_job(job) is True
- assert calls >= 3
+ assert cancellation_after[0] >= scheduler._FIRE_CLAIM_HEARTBEAT_GRACE_SECONDS
def test_terminal_owner_cas_failure_marks_ledger_ownership_lost(monkeypatch):