From ad4fd007ab4e72e6eda7fee263b8976c19aa993b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Tue, 26 Jul 2022 15:14:15 +0300 Subject: Improved the scheduler lifecycle management Both sync and async schedulers now have consistently working stop() and wait_until_stopped() methods. --- tests/test_schedulers.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/test_schedulers.py b/tests/test_schedulers.py index e33a91e..ab49abe 100644 --- a/tests/test_schedulers.py +++ b/tests/test_schedulers.py @@ -214,6 +214,17 @@ class TestAsyncScheduler: else: assert result.outcome is JobOutcome.success + async def test_wait_until_stopped(self) -> None: + async with AsyncScheduler() as scheduler: + trigger = DateTrigger( + datetime.now(timezone.utc) + timedelta(milliseconds=100) + ) + await scheduler.add_schedule(scheduler.stop, trigger) + await scheduler.wait_until_stopped() + + # This should be a no-op + await scheduler.wait_until_stopped() + class TestSyncScheduler: def test_schedule_job(self): @@ -365,3 +376,14 @@ class TestSyncScheduler: raise result.exception else: assert result.outcome is JobOutcome.success + + def test_wait_until_stopped(self) -> None: + with Scheduler() as scheduler: + trigger = DateTrigger( + datetime.now(timezone.utc) + timedelta(milliseconds=100) + ) + scheduler.add_schedule(scheduler.stop, trigger) + scheduler.wait_until_stopped() + + # This should be a no-op + scheduler.wait_until_stopped() -- cgit v1.2.1