@@ -575,7 +575,7 @@ def __test_task_execution_lifecycle(self):
575575 assert self .task_client .get_queue_size_for_task (TASK_TYPE ) == 1
576576
577577 taskResult = TaskResult (
578- workflow_instance_id = workflow_uuid ,
578+ workflow_instance_id = polledTask . workflow_instance_id ,
579579 task_id = polledTask .task_id ,
580580 status = TaskResultStatus .COMPLETED
581581 )
@@ -585,34 +585,41 @@ def __test_task_execution_lifecycle(self):
585585 task = self .task_client .get_task (polledTask .task_id )
586586 assert task .status == TaskResultStatus .COMPLETED
587587
588- batchPolledTasks = self .task_client .batch_poll_tasks (TASK_TYPE )
589- assert len (batchPolledTasks ) == 1
590-
591- polledTask = batchPolledTasks [0 ]
592- # Update first task of second workflow
593- _retry_on_404 (
594- self .task_client .update_task_by_ref_name ,
595- workflow_uuid_2 ,
596- polledTask .reference_task_name ,
597- "COMPLETED" ,
598- "task 2 op 2nd wf"
599- )
600-
601- # Update second task of first workflow
602- _retry_on_404 (
603- self .task_client .update_task_by_ref_name ,
604- workflow_uuid_2 , "simple_task_ref_2" , "COMPLETED" , "task 2 op 1st wf"
605- )
588+ # The second task of the first workflow and both tasks of the second
589+ # workflow all share TASK_TYPE and land in the same queue, so a poll can
590+ # return a task from either workflow in a non-deterministic order. Drive
591+ # every update from the polled task's own workflow id and reference name
592+ # instead of assuming which workflow/ref we got back (the previous
593+ # hardcoded workflow_uuid_2 / "simple_task_ref_2" pairing produced
594+ # spurious 404s whenever the queue handed back the other workflow's
595+ # task). We still exercise update_task_by_ref_name and update_task_sync.
606596
607- # # Second task of second workflow is in the queue
608- # assert self.task_client.getQueueSizeForTask(TASK_TYPE) == 1
609- polledTask = self .task_client .poll_task (TASK_TYPE )
610-
611- # Update second task of second workflow
612- _retry_on_404 (
613- self .task_client .update_task_sync ,
614- workflow_uuid , "simple_task_ref_2" , "COMPLETED" , "task 1 op 2nd wf"
615- )
597+ # Three task executions remain (we completed one above); drain them all.
598+ batchPolledTasks = self .task_client .batch_poll_tasks (TASK_TYPE )
599+ remaining = 3
600+ completed = 0
601+ for polledTask in batchPolledTasks :
602+ _retry_on_404 (
603+ self .task_client .update_task_by_ref_name ,
604+ polledTask .workflow_instance_id ,
605+ polledTask .reference_task_name ,
606+ "COMPLETED" ,
607+ f"task op { completed + 1 } (by ref name)"
608+ )
609+ completed += 1
610+
611+ while completed < remaining :
612+ polledTask = self .task_client .poll_task (TASK_TYPE )
613+ assert polledTask is not None , \
614+ "expected a task to be available to poll while draining the queue"
615+ _retry_on_404 (
616+ self .task_client .update_task_sync ,
617+ polledTask .workflow_instance_id ,
618+ polledTask .reference_task_name ,
619+ "COMPLETED" ,
620+ f"task op { completed + 1 } (sync)"
621+ )
622+ completed += 1
616623
617624 queue_size = self .task_client .get_queue_size_for_task (TASK_TYPE )
618625 print (f'queue size for { TASK_TYPE } is { queue_size } ' )
0 commit comments