2020 [
2121 pytest .param ([{"cron" : "* * * * *" }], id = "cron" ),
2222 pytest .param ([{"time" : datetime .now (pytz .UTC )}], id = "time" ),
23+ pytest .param (
24+ [{"time" : datetime .now (pytz .UTC ), "labels" : {"foo" : "bar" }}],
25+ id = "labels_inside_schedule" ,
26+ ),
27+ pytest .param (
28+ [{"cron" : "*/1 * * * *" , "schedule_id" : "every_minute" }],
29+ id = "schedule_with_id" ,
30+ ),
2331 ],
2432)
2533async def test_label_discovery (schedule_label : List [Dict [str , Any ]]) -> None :
@@ -37,16 +45,20 @@ def task() -> None:
3745 schedules = await source .get_schedules ()
3846 assert schedules == [
3947 ScheduledTask (
40- schedule_id = schedules [0 ].schedule_id ,
48+ schedule_id = schedule_label [ 0 ]. get ( "schedule_id" , schedules [0 ].schedule_id ) ,
4149 cron = schedule_label [0 ].get ("cron" ),
4250 time = schedule_label [0 ].get ("time" ),
4351 task_name = "test_task" ,
44- labels = { "schedule" : schedule_label } ,
52+ labels = schedule_label [ 0 ]. get ( "labels" , {}) ,
4553 args = [],
4654 kwargs = {},
4755 ),
4856 ]
4957
58+ # check that labels of tasks are not changed after startup and discovery process
59+ task_from_broker = next (iter (broker .get_all_tasks ().values ()))
60+ assert task_from_broker .labels == {"schedule" : schedule_label }
61+
5062
5163@pytest .mark .anyio
5264async def test_label_discovery_no_cron () -> None :
0 commit comments