mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 16:48:30 +00:00
fix: gracefully terminate the future when executing a task async
* fix: gracefully terminate the future when executing a task async * core: add unit test --------- Co-authored-by: Greyson LaLonde <greyson.r.lalonde@gmail.com>
This commit is contained in:
committed by
GitHub
parent
e43c7debbd
commit
feec6b440e
@@ -1727,3 +1727,24 @@ def test_task_output_includes_messages():
|
||||
assert hasattr(task2_output, "messages")
|
||||
assert isinstance(task2_output.messages, list)
|
||||
assert len(task2_output.messages) > 0
|
||||
|
||||
|
||||
def test_async_execution_fails():
|
||||
researcher = Agent(
|
||||
role="Researcher",
|
||||
goal="Make the best research and analysis on content about AI and AI agents",
|
||||
backstory="You're an expert researcher, specialized in technology, software engineering, AI and startups. You work as a freelancer and is now working on doing research and analysis for a new customer.",
|
||||
allow_delegation=False,
|
||||
)
|
||||
|
||||
task = Task(
|
||||
description="Give me a list of 5 interesting ideas to explore for na article, what makes them unique and interesting.",
|
||||
expected_output="Bullet point list of 5 interesting ideas.",
|
||||
async_execution=True,
|
||||
agent=researcher,
|
||||
)
|
||||
|
||||
with patch.object(Task, "_execute_core", side_effect=RuntimeError("boom!")):
|
||||
with pytest.raises(RuntimeError, match="boom!"):
|
||||
execution = task.execute_async(agent=researcher)
|
||||
execution.result()
|
||||
|
||||
Reference in New Issue
Block a user