From 17c96d00d2f58c23038f71687b4d92979f2b5944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=85=B1=E7=89=9B=E8=82=89?= Date: Tue, 27 Oct 2026 15:00:58 +0800 Subject: [PATCH] test: wait for pipeline descendants to exit after cancellation --- plugins/home/tests/test_auto_bash.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/home/tests/test_auto_bash.py b/plugins/home/tests/test_auto_bash.py index ed497e4c..c8f7ddfc 100644 --- a/plugins/home/tests/test_auto_bash.py +++ b/plugins/home/tests/test_auto_bash.py @@ -107,7 +107,21 @@ async def test_local_pipeline_timeout_and_cancellation(tmp_path, monkeypatch, ba assert "timed out after 100ms" in response.answer assert descendants assert processes[0].returncode is not None - assert all(not child.is_running() or child.status() == psutil.STATUS_ZOMBIE for child in descendants) + + async def descendants_stopped(): + # Pipe EOF can precede exit after SIGKILL, especially for orphaned background children. + pending = descendants.copy() + while pending: + for child in pending.copy(): + try: + if not child.is_running() or child.status() == psutil.STATUS_ZOMBIE: + pending.remove(child) + except psutil.NoSuchProcess: + pending.remove(child) + if pending: + await asyncio.sleep(0.01) + + await asyncio.wait_for(descendants_stopped(), timeout=1) finally: if not task.done(): task.cancel()