Files
hub/test_cancellation.py
T

49 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""
Simple test script to verify agent run cancellation functionality.
"""
import asyncio
import sys
import os
# Add the backend directory to the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend'))
from src.app import App
from src.agent import AgentRun
async def test_cancellation():
print("Testing agent run cancellation...")
# Create a mock app
app = App(data_directory="/tmp/horde_test")
# Create an agent run
run = AgentRun.create(app, agent_id="test-agent", user_id="test-user")
print(f"Created agent run: {run.id}")
# Test that the run is not cancelled initially
assert not run.cancelled, "Run should not be cancelled initially"
print("✓ Run is not cancelled initially")
# Test cancellation
run.cancel()
assert run.cancelled, "Run should be cancelled after calling cancel()"
assert run.done, "Run should be marked as done after cancellation"
print("✓ Run is cancelled and marked as done")
# Test that calling cancel again doesn't cause issues
run.cancel()
print("✓ Multiple cancel calls work correctly")
# Test that the run has the expected attributes
assert hasattr(run, 'task'), "Run should have a task attribute"
assert hasattr(run, 'thread'), "Run should have a thread attribute"
assert hasattr(run, 'cancelled'), "Run should have a cancelled attribute"
print("✓ Run has all required cancellation attributes")
print("All tests passed! Cancellation functionality is working correctly.")
if __name__ == "__main__":
asyncio.run(test_cancellation())