sched: record resumed stopped results live and idempotently (B3)
This commit is contained in:
@@ -384,3 +384,89 @@ def test_manual_and_other_schedule_runs_are_overlap_independent(
|
||||
assert result["a"].startswith("admit:run-")
|
||||
assert result["b"] == "exhausted"
|
||||
sched.ownership.release()
|
||||
|
||||
|
||||
def test_record_resumed_stopped_result_is_idempotent_and_attributed(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""Live resumed results record exactly once with schedule attribution (B3)."""
|
||||
from wf_api.run_lifecycle import persist_admission
|
||||
|
||||
from tests.scheduling.controlled import fixture_environment
|
||||
|
||||
sched, store, runs, sources = _harness(tmp_path, script={"*": "interrupt"})
|
||||
t0 = ts(2026, 9, 8, 12, 0)
|
||||
_add(sched, store, sources, "a", OneShotSource(t0), t0 - timedelta(seconds=1))
|
||||
assert sched.poll(t0)["a"].startswith("admit:run-")
|
||||
[run] = runs.list_runs()
|
||||
assert run.status.value == "interrupted"
|
||||
assert len([r for r in _history(store, "a") if r["kind"] == "interrupted"]) == 1
|
||||
|
||||
now = t0 + timedelta(minutes=1)
|
||||
resumed_ckpt = f"{run.id}.000002"
|
||||
assert (
|
||||
sched.record_resumed_stopped_result(
|
||||
run.id,
|
||||
status_value="completed",
|
||||
checkpoint_id=resumed_ckpt,
|
||||
now=now,
|
||||
)
|
||||
is True
|
||||
)
|
||||
# Repeats (poll retries, restart recovery) never duplicate the entry.
|
||||
assert (
|
||||
sched.record_resumed_stopped_result(
|
||||
run.id,
|
||||
status_value="completed",
|
||||
checkpoint_id=resumed_ckpt,
|
||||
now=now,
|
||||
)
|
||||
is False
|
||||
)
|
||||
completed = [r for r in _history(store, "a") if r["kind"] == "completed"]
|
||||
assert len(completed) == 1
|
||||
assert completed[0]["run_id"] == run.id
|
||||
assert completed[0]["checkpoint_id"] == resumed_ckpt
|
||||
assert completed[0]["revision"] == 1
|
||||
assert completed[0]["reason"] == "resumed"
|
||||
# A resumed re-interruption is a new result (new checkpoint), not a dup.
|
||||
assert (
|
||||
sched.record_resumed_stopped_result(
|
||||
run.id,
|
||||
status_value="interrupted",
|
||||
checkpoint_id=f"{run.id}.000003",
|
||||
now=now,
|
||||
)
|
||||
is True
|
||||
)
|
||||
assert len([r for r in _history(store, "a") if r["kind"] == "interrupted"]) == 2
|
||||
# Unknown runs, manual runs, and bad statuses record nothing.
|
||||
assert (
|
||||
sched.record_resumed_stopped_result(
|
||||
"run-999999",
|
||||
status_value="completed",
|
||||
checkpoint_id=None,
|
||||
now=now,
|
||||
)
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
sched.record_resumed_stopped_result(
|
||||
run.id, status_value="bogus", checkpoint_id=None, now=now
|
||||
)
|
||||
is False
|
||||
)
|
||||
manual = persist_admission(
|
||||
store=runs,
|
||||
run_id=runs.allocate_run_id(),
|
||||
environment=fixture_environment(object()),
|
||||
resolved_input={},
|
||||
max_steps=None,
|
||||
)
|
||||
assert (
|
||||
sched.record_resumed_stopped_result(
|
||||
manual.id, status_value="completed", checkpoint_id=None, now=now
|
||||
)
|
||||
is False
|
||||
)
|
||||
sched.ownership.release()
|
||||
|
||||
Reference in New Issue
Block a user