Fix session cancel and new task routing
This commit is contained in:
@@ -349,6 +349,29 @@ class GuiServerTests(unittest.TestCase):
|
||||
self.assertIsNotNone(row)
|
||||
self.assertEqual(row['status'], 'cancelled')
|
||||
|
||||
def test_cancel_run_abandons_held_session_lock(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
client, state = _build_client(Path(d))
|
||||
record = state.run_manager.start('alice', 'thread-1')
|
||||
old_lock = state.run_lock_for('alice', 'thread-1')
|
||||
self.assertTrue(old_lock.acquire(blocking=False))
|
||||
old_agent = state.agent_for('alice', 'thread-1')
|
||||
try:
|
||||
response = client.post(
|
||||
'/api/runs/cancel',
|
||||
json={'account_id': 'alice', 'session_id': 'thread-1'},
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTrue(response.json()['cancelled'])
|
||||
self.assertTrue(record.cancel_event.is_set())
|
||||
new_lock = state.run_lock_for('alice', 'thread-1')
|
||||
self.assertIsNot(new_lock, old_lock)
|
||||
self.assertTrue(new_lock.acquire(blocking=False))
|
||||
new_lock.release()
|
||||
self.assertIsNot(state.agent_for('alice', 'thread-1'), old_agent)
|
||||
finally:
|
||||
old_lock.release()
|
||||
|
||||
def test_latest_run_prefers_running_over_queued_for_session(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
client, state = _build_client(Path(d))
|
||||
|
||||
Reference in New Issue
Block a user