import asyncio import sys import pytest from services import render_service @pytest.fixture(autouse=True) def fake_renderer(monkeypatch, tmp_path): # 이 파일은 conftest의 렌더 대역 대신 실제 자식 프로세스 수명만 검사한다. monkeypatch.setenv("SITE_OUTPUT_DIR", str(tmp_path)) async def test_process_success(): code, _ = await render_service._run_subprocess([sys.executable, "-c", "print(1)"], 2) assert code == 0 async def test_timeout_releases_lock(): code, _ = await render_service._run_subprocess( [sys.executable, "-c", "import time;time.sleep(5)"], 0.1 ) assert code is None code, _ = await render_service._run_subprocess([sys.executable, "-c", "print(1)"], 2) assert code == 0 async def test_cancel_releases_lock(): task = asyncio.create_task(render_service._run_subprocess( [sys.executable, "-c", "import time;time.sleep(5)"], 10 )) await asyncio.sleep(0.1) task.cancel() with pytest.raises(asyncio.CancelledError): await task code, _ = await render_service._run_subprocess([sys.executable, "-c", "print(1)"], 2) assert code == 0