@@ -27,6 +27,24 @@ async def test_schedule_cron(redis_url: str) -> None:
2727 assert scehdules == [schedule ]
2828
2929
30+ @pytest .mark .anyio
31+ @freeze_time ("2025-01-01 00:00:00" )
32+ async def test_schedule_interval (redis_url : str ) -> None :
33+ """Test adding a cron schedule."""
34+ prefix = uuid .uuid4 ().hex
35+ source = ListRedisScheduleSource (redis_url , prefix = prefix )
36+ schedule = ScheduledTask (
37+ task_name = "test_task" ,
38+ labels = {},
39+ args = [],
40+ kwargs = {},
41+ interval = datetime .timedelta (seconds = 5 ),
42+ )
43+ await source .add_schedule (schedule )
44+ scehdules = await source .get_schedules ()
45+ assert scehdules == [schedule ]
46+
47+
3048@pytest .mark .anyio
3149@freeze_time ("2025-01-01 00:00:00" )
3250async def test_schedule_from_past (redis_url : str ) -> None :
@@ -56,7 +74,7 @@ async def test_schedule_from_past(redis_url: str) -> None:
5674
5775@pytest .mark .anyio
5876@freeze_time ("2025-01-01 00:00:00" )
59- async def test_schedule_removal (redis_url : str ) -> None :
77+ async def test_removal_time (redis_url : str ) -> None :
6078 """Test adding a cron schedule."""
6179 prefix = uuid .uuid4 ().hex
6280 source = ListRedisScheduleSource (redis_url , prefix = prefix )
@@ -81,16 +99,39 @@ async def test_schedule_removal(redis_url: str) -> None:
8199
82100@pytest .mark .anyio
83101@freeze_time ("2025-01-01 00:00:00" )
84- async def test_deletion (redis_url : str ) -> None :
85- """Test adding a cron schedule."""
102+ async def test_removal_cron (redis_url : str ) -> None :
103+ """Test removing cron schedules."""
104+ prefix = uuid .uuid4 ().hex
105+ source = ListRedisScheduleSource (redis_url , prefix = prefix )
106+ schedule = ScheduledTask (
107+ task_name = "test_task" ,
108+ labels = {},
109+ args = [],
110+ kwargs = {},
111+ cron = "* * * * *" ,
112+ )
113+ await source .add_schedule (schedule )
114+ # When running for the first time, the scheduler will get all the
115+ # schedules that are in the past.
116+ scehdules = await source .get_schedules ()
117+ assert scehdules == [schedule ]
118+ await source .delete_schedule (schedule .schedule_id )
119+ scehdules = await source .get_schedules ()
120+ assert scehdules == []
121+
122+
123+ @pytest .mark .anyio
124+ @freeze_time ("2025-01-01 00:00:00" )
125+ async def test_removal_interval (redis_url : str ) -> None :
126+ """Test removing cron schedules."""
86127 prefix = uuid .uuid4 ().hex
87128 source = ListRedisScheduleSource (redis_url , prefix = prefix )
88129 schedule = ScheduledTask (
89130 task_name = "test_task" ,
90131 labels = {},
91132 args = [],
92133 kwargs = {},
93- time = datetime .datetime . now ( datetime . timezone . utc ),
134+ interval = datetime .timedelta ( seconds = 30 ),
94135 )
95136 await source .add_schedule (schedule )
96137 # When running for the first time, the scheduler will get all the
0 commit comments