@@ -732,7 +732,7 @@ async def on_task_status(task_result: GetTaskResult) -> None:
732732 # Test begin_call_tool for task-based execution
733733 pending_request = session .begin_call_tool (
734734 "long_running_computation" ,
735- arguments = {"data" : "test_data" , "delay_seconds" : 0. 1 },
735+ arguments = {"data" : "test_data" , "delay_seconds" : 1 },
736736 )
737737
738738 # Wait for the result with callbacks
@@ -744,8 +744,25 @@ async def on_task_status(task_result: GetTaskResult) -> None:
744744 assert len (tool_result .content ) == 1
745745 assert isinstance (tool_result .content [0 ], TextContent )
746746 assert "Processed: TEST_DATA" in tool_result .content [0 ].text
747- assert "0.1s " in tool_result .content [0 ].text
747+ assert "1s" in tool_result . content [ 0 ]. text or "1.0s " in tool_result .content [0 ].text
748748
749- # Note: Due to the race between direct result and task-based polling,
750- # callbacks may or may not be called depending on timing.
751- # The important thing is that task-based execution is supported and works correctly.
749+ # Verify callbacks were invoked
750+ assert task_created_called , "on_task_created callback was not invoked"
751+ assert len (task_status_updates ) > 0 , "on_task_status callback was never invoked"
752+
753+ # Due to the race between direct result and task polling:
754+ # - With 1s delay and 5s default polling interval, direct result usually wins
755+ # - We should see at least one status update (typically "submitted")
756+ # - We may or may not see "completed" depending on timing
757+
758+ # Verify we got at least one valid status
759+ valid_statuses = ["submitted" , "working" , "completed" ]
760+ assert all (status in valid_statuses for status in task_status_updates ), (
761+ f"Got invalid status in updates: { task_status_updates } "
762+ )
763+
764+ # If direct result won the race, we may only see submitted/working; if polling won, we'll see completed
765+ last_status = task_status_updates [- 1 ]
766+ assert last_status in ["submitted" , "working" , "completed" ], (
767+ f"Unexpected last status: { last_status } from { task_status_updates } "
768+ )
0 commit comments