mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-09-14 14:05:20 +03:00
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.
This commit is contained in:
parent
fa282e0f82
commit
0c540abbf2
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user