Skip to content

Commit d29c215

Browse files
committed
Fix failing task test
1 parent 5abe554 commit d29c215

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

tests/server/fastmcp/test_integration.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,11 @@ async def on_task_status(task_result: GetTaskResult) -> None:
733733
task_status_updates.append(task_result.status)
734734

735735
# Test begin_call_tool for task-based execution
736+
# Use a longer delay (10s) to ensure the polling path has time to get status updates
737+
# before the direct result completes (default poll interval is 5s)
736738
pending_request = session.begin_call_tool(
737739
"long_running_computation",
738-
arguments={"data": "test_data", "delay_seconds": 1},
740+
arguments={"data": "test_data", "delay_seconds": 10},
739741
)
740742

741743
# Wait for the result with callbacks
@@ -747,25 +749,23 @@ async def on_task_status(task_result: GetTaskResult) -> None:
747749
assert len(tool_result.content) == 1
748750
assert isinstance(tool_result.content[0], TextContent)
749751
assert "Processed: TEST_DATA" in tool_result.content[0].text
750-
assert "1s" in tool_result.content[0].text or "1.0s" in tool_result.content[0].text
752+
assert "10" in tool_result.content[0].text or "10.0s" in tool_result.content[0].text
751753

752754
# Verify callbacks were invoked
753755
assert task_created_called, "on_task_created callback was not invoked"
754756
assert len(task_status_updates) > 0, "on_task_status callback was never invoked"
755757

756-
# Due to the race between direct result and task polling:
757-
# - With 1s delay and 5s default polling interval, direct result usually wins
758-
# - We should see at least one status update (typically "submitted")
759-
# - We may or may not see "completed" depending on timing
758+
# With 10s delay and 5s default polling interval, polling should get at least one update
759+
# before the task completes
760+
# We should see at least "submitted" and possibly "working" or "completed"
760761

761762
# Verify we got at least one valid status
762763
valid_statuses = ["submitted", "working", "completed"]
763764
assert all(status in valid_statuses for status in task_status_updates), (
764765
f"Got invalid status in updates: {task_status_updates}"
765766
)
766767

767-
# If direct result won the race, we may only see submitted/working; if polling won, we'll see completed
768-
last_status = task_status_updates[-1]
769-
assert last_status in ["submitted", "working", "completed"], (
770-
f"Unexpected last status: {last_status} from {task_status_updates}"
768+
# Verify we got at least the initial status
769+
assert "submitted" in task_status_updates or "working" in task_status_updates, (
770+
f"Expected to see submitted or working status, got: {task_status_updates}"
771771
)

0 commit comments

Comments
 (0)