-
-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathtest_scheduler.py
More file actions
43 lines (30 loc) · 1.23 KB
/
test_scheduler.py
File metadata and controls
43 lines (30 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import asyncio
import contextlib
from datetime import datetime, timedelta, timezone
from taskiq import TaskiqScheduler
from taskiq.api import run_scheduler_task
from taskiq.schedule_sources import LabelScheduleSource
from tests.utils import AsyncQueueBroker
async def test_successful() -> None:
broker = AsyncQueueBroker()
scheduler = TaskiqScheduler(broker, sources=[LabelScheduleSource(broker)])
scheduler_task = asyncio.create_task(run_scheduler_task(scheduler))
@broker.task(schedule=[{"time": datetime.now(timezone.utc) - timedelta(seconds=1)}])
def _() -> None:
...
msg = await asyncio.wait_for(broker.queue.get(), 0.3)
assert msg
scheduler_task.cancel()
async def test_cancelation() -> None:
broker = AsyncQueueBroker()
scheduler = TaskiqScheduler(broker, sources=[LabelScheduleSource(broker)])
@broker.task(schedule=[{"time": datetime.now(timezone.utc)}])
def _() -> None:
...
scheduler_task = asyncio.create_task(run_scheduler_task(scheduler))
msg = await asyncio.wait_for(broker.queue.get(), 0.3)
assert msg
scheduler_task.cancel()
with contextlib.suppress(asyncio.CancelledError):
await scheduler_task
assert scheduler_task.cancelled()