From ea92bbc5c2526745a5e7223b1767ea5649e91bd7 Mon Sep 17 00:00:00 2001 From: KoNit-K <124019182+KoNit-K@users.noreply.github.com> Date: Tue, 15 Sep 2026 10:19:02 +0800 Subject: [PATCH] test(cron): stabilize heartbeat grace assertion --- tests/cron/test_script_claim_heartbeat.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/cron/test_script_claim_heartbeat.py b/tests/cron/test_script_claim_heartbeat.py index 1903b78fff..1b6d7f74d7 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):