From 0c540abbf295e8746c66564eb9f9c3625c273ea5 Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Tue, 8 Sep 2026 00:04:04 +0800 Subject: [PATCH] fix: stop leaking a global os.kill mock from the shutdown route test The bare 'os.kill = MagicMock()' was never restored, so every later test in the same process ran with a no-op kill. Any test that kills a child process and waits for it then hangs forever (resident sharkd sessions waiting on an immortal process). Use monkeypatch so the patch is undone. --- tests/api/routes/controller/test_controller.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/api/routes/controller/test_controller.py b/tests/api/routes/controller/test_controller.py index ddd33aa8e..43d672302 100644 --- a/tests/api/routes/controller/test_controller.py +++ b/tests/api/routes/controller/test_controller.py @@ -29,13 +29,18 @@ pytestmark = pytest.mark.asyncio class TestControllerRoutes: - async def test_shutdown_local(self, app: FastAPI, client: AsyncClient, config: Config) -> None: - - os.kill = MagicMock() + async def test_shutdown_local(self, app: FastAPI, client: AsyncClient, config: Config, monkeypatch) -> None: + + # monkeypatch (not bare assignment): a global `os.kill = MagicMock()` + # is never restored and poisons every later test that kills a + # subprocess — resident sharkd sessions would wait() forever on an + # immortal process. + kill_mock = MagicMock() + monkeypatch.setattr(os, "kill", kill_mock) config.settings.Server.local = True response = await client.post(app.url_path_for("shutdown")) assert response.status_code == status.HTTP_204_NO_CONTENT - assert os.kill.called + assert kill_mock.called async def test_shutdown_non_local(self, app: FastAPI, client: AsyncClient, config: Config) -> None: