Unverified Commit 45bc1b79 authored by MatejKosec's avatar MatejKosec Committed by GitHub
Browse files

fix: use tempfile.TemporaryDirectory in load generator test (#6196)


Signed-off-by: default avatarMatej Kosec <mkosec@nvidia.com>
parent 4220771f
...@@ -10,6 +10,7 @@ preventing orphaned child processes from holding pipe FDs and causing hangs. ...@@ -10,6 +10,7 @@ preventing orphaned child processes from holding pipe FDs and causing hangs.
import asyncio import asyncio
import signal import signal
import tempfile
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
import pytest import pytest
...@@ -23,7 +24,7 @@ pytestmark = [ ...@@ -23,7 +24,7 @@ pytestmark = [
] ]
def test_timeout_kills_process_group(tmp_path): def test_timeout_kills_process_group():
"""On timeout, the entire process group must be killed via os.killpg.""" """On timeout, the entire process group must be killed via os.killpg."""
target_pid = 99999 target_pid = 99999
generator = LoadGenerator() generator = LoadGenerator()
...@@ -42,14 +43,15 @@ def test_timeout_kills_process_group(tmp_path): ...@@ -42,14 +43,15 @@ def test_timeout_kills_process_group(tmp_path):
raise asyncio.TimeoutError() raise asyncio.TimeoutError()
async def _run(): async def _run():
with ( with tempfile.TemporaryDirectory() as tmp_dir:
patch("asyncio.create_subprocess_exec", side_effect=fake_exec), with (
patch("asyncio.wait_for", side_effect=fake_wait_for), patch("asyncio.create_subprocess_exec", side_effect=fake_exec),
patch("os.killpg") as mock_killpg, patch("asyncio.wait_for", side_effect=fake_wait_for),
): patch("os.killpg") as mock_killpg,
with pytest.raises(RuntimeError, match="timed out"): ):
await generator.generate_load(1.0, 1, str(tmp_path)) with pytest.raises(RuntimeError, match="timed out"):
await generator.generate_load(1.0, 1, tmp_dir)
mock_killpg.assert_called_once_with(target_pid, signal.SIGKILL)
mock_killpg.assert_called_once_with(target_pid, signal.SIGKILL)
asyncio.run(_run()) asyncio.run(_run())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment