test: isolate lifecycle shutdown contracts

This commit is contained in:
jxxghp
2026-08-23 23:33:07 +08:00
parent 6e69258e3c
commit 57e9d11f67
3 changed files with 22 additions and 16 deletions
+8 -1
View File
@@ -319,15 +319,22 @@ async def test_stop_retains_running_blocking_tool_until_retry(monkeypatch) -> No
started = threading.Event()
release = threading.Event()
assert reopen_blocking_executors() is True
def _blocking_call() -> str:
started.set()
release.wait()
return "done"
async def _wait_until_started() -> None:
"""等待阻塞工具线程启动,避免把永久等待任务留在默认线程池。"""
while not started.is_set():
await asyncio.sleep(0)
worker = asyncio.create_task(
MoviePilotTool.run_blocking("web", _blocking_call)
)
assert await asyncio.wait_for(asyncio.to_thread(started.wait), timeout=1)
await asyncio.wait_for(_wait_until_started(), timeout=1)
monkeypatch.setattr(
agent_initializer,
"begin_agent_shutdown",