mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-04 02:01:48 +03:00
fix: queue concurrent subagents (#5566)
* fix: queue concurrent subagents * chore: keep spawn schema concise
This commit is contained in:
@@ -520,6 +520,35 @@ class TestCancelBySession:
|
||||
count = await sm.cancel_by_session("nonexistent")
|
||||
assert count == 0
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_cancels_active_and_queued_tasks(self, tmp_path):
|
||||
sm = _manager(tmp_path, max_concurrent_subagents=1)
|
||||
active_entered = asyncio.Event()
|
||||
queued_entered = asyncio.Event()
|
||||
|
||||
async def _blocked_run(spec):
|
||||
task = spec.initial_messages[-1]["content"]
|
||||
if task == "active":
|
||||
active_entered.set()
|
||||
else:
|
||||
queued_entered.set()
|
||||
await asyncio.Event().wait()
|
||||
|
||||
sm.runner.run = _blocked_run
|
||||
runtime = _runtime()
|
||||
await sm.spawn("active", runtime=runtime, session_key="s1")
|
||||
await asyncio.wait_for(active_entered.wait(), timeout=1.0)
|
||||
await sm.spawn("queued", runtime=runtime, session_key="s1")
|
||||
await asyncio.sleep(0)
|
||||
|
||||
assert not queued_entered.is_set()
|
||||
assert await sm.cancel_by_session("s1") == 2
|
||||
await asyncio.sleep(0)
|
||||
|
||||
assert not queued_entered.is_set()
|
||||
assert sm._running_tasks == {}
|
||||
assert sm._session_tasks == {}
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_already_done_not_counted(self, tmp_path):
|
||||
sm = _manager(tmp_path)
|
||||
|
||||
Reference in New Issue
Block a user