test(cron): avoid Windows timer race

Disable the externally updated cron job before yielding to the event loop so slow Windows CI cannot run the short-interval job before the test writes the update.
This commit is contained in:
Xubin Ren 2026-05-05 16:28:20 +00:00 committed by Xubin Ren
parent db14685a69
commit e54fbfeb2a

View File

@ -228,8 +228,9 @@ async def test_running_service_honors_external_disable(tmp_path) -> None:
) )
await service.start() await service.start()
try: try:
# Wait slightly to ensure file mtime is definitively different # Disable before yielding back to the event loop. On slower Windows CI
await asyncio.sleep(0.05) # a short sleep here can overrun the 200ms schedule and let the job fire
# before the external update is written.
external = CronService(store_path) external = CronService(store_path)
updated = external.enable_job(job.id, enabled=False) updated = external.enable_job(job.id, enabled=False)
assert updated is not None assert updated is not None
@ -552,7 +553,7 @@ def test_update_job_offline_writes_action(tmp_path) -> None:
action_path = tmp_path / "cron" / "action.jsonl" action_path = tmp_path / "cron" / "action.jsonl"
assert action_path.exists() assert action_path.exists()
lines = [l for l in action_path.read_text().strip().split("\n") if l] lines = [line for line in action_path.read_text().strip().split("\n") if line]
last = json.loads(lines[-1]) last = json.loads(lines[-1])
assert last["action"] == "update" assert last["action"] == "update"
assert last["params"]["name"] == "updated-offline" assert last["params"]["name"] == "updated-offline"