From e152e7bc0bf646ccc31aa33622fb0d037edc2701 Mon Sep 17 00:00:00 2001 From: Xubin Ren <52506698+Re-bin@users.noreply.github.com> Date: Sat, 1 Aug 2026 11:33:14 +0800 Subject: [PATCH] test(cron): cover stop during manual execution --- tests/cron/test_cron_service.py | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/cron/test_cron_service.py b/tests/cron/test_cron_service.py index 7623fdd41..f91bf2b89 100644 --- a/tests/cron/test_cron_service.py +++ b/tests/cron/test_cron_service.py @@ -677,6 +677,40 @@ async def test_overlapping_manual_runs_preserve_stopped_service_state(tmp_path) service.stop() +@pytest.mark.asyncio +async def test_manual_run_does_not_restart_service_stopped_during_execution(tmp_path) -> None: + store_path = tmp_path / "cron" / "jobs.json" + entered = asyncio.Event() + release = asyncio.Event() + + async def on_job(_job) -> None: + entered.set() + await release.wait() + + service = CronService(store_path, on_job=on_job) + job = service.add_job( + name="manual-stop", + schedule=CronSchedule(kind="every", every_ms=60_000), + message="hello", + **_bound_chat(), + ) + await service.start() + + run = asyncio.create_task(service.run_job(job.id)) + try: + await entered.wait() + service.stop() + release.set() + + assert await run is True + assert service._running is False + assert service._timer_task is None + finally: + release.set() + await asyncio.gather(run, return_exceptions=True) + service.stop() + + @pytest.mark.asyncio async def test_running_service_honors_external_disable(tmp_path) -> None: store_path = tmp_path / "cron" / "jobs.json"