From e54fbfeb2a033394af3f5d896d0f04c01e83fe39 Mon Sep 17 00:00:00 2001 From: Xubin Ren Date: Tue, 5 May 2026 16:28:20 +0000 Subject: [PATCH] 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. --- tests/cron/test_cron_service.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/cron/test_cron_service.py b/tests/cron/test_cron_service.py index 1f000dbd7..fa304e06e 100644 --- a/tests/cron/test_cron_service.py +++ b/tests/cron/test_cron_service.py @@ -228,8 +228,9 @@ async def test_running_service_honors_external_disable(tmp_path) -> None: ) await service.start() try: - # Wait slightly to ensure file mtime is definitively different - await asyncio.sleep(0.05) + # Disable before yielding back to the event loop. On slower Windows CI + # a short sleep here can overrun the 200ms schedule and let the job fire + # before the external update is written. external = CronService(store_path) updated = external.enable_job(job.id, enabled=False) 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" 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]) assert last["action"] == "update" assert last["params"]["name"] == "updated-offline"