Files
svcforge/tests/integration/test_helm_timeout.py
T
Nguyen Minh Phuc 50c2fe2a1e
ci / lint (push) Successful in 1m19s
ci / unit (push) Failing after 1m2s
ci / integration (push) Has been skipped
ci / types (push) Successful in 1m37s
ci / security (push) Failing after 38s
ci / dockerfile (push) Successful in 14s
ci / image (api) (push) Has been skipped
ci / image (reconciler) (push) Has been skipped
ci / image (worker) (push) Has been skipped
ci / bump (push) Has been skipped
svcforge: reference implementation
Complete working build of the system learn-python/ teaches.
164 tests, mypy --strict clean, domain coverage 99%.
2026-07-17 10:44:54 +00:00

30 lines
1.1 KiB
Python

"""The one test that proves the timeout is real.
`bash -c "sleep 300 & sleep 300"` is a miniature helm: a process that forks a child and
waits on another. Kill the direct child only and the backgrounded `sleep` reparents to init
and keeps running — which, when the process is helm, means a timed-out task retries while
the original helm is still mutating the same release.
This test needs a real process tree, so it lives in integration/. It needs no database:
the `pool` fixture in conftest is not autouse.
"""
from __future__ import annotations
import asyncio
import subprocess
import pytest
from svcforge_core.adapters.helm import _run
@pytest.mark.asyncio
async def test_timeout_kills_the_whole_process_group() -> None:
argv = ["bash", "-c", "sleep 300 & sleep 300"] # child forks a grandchild
with pytest.raises(TimeoutError):
await _run(argv, timeout_s=1)
await asyncio.sleep(0.5)
out = subprocess.run(["pgrep", "-f", "sleep 300"], capture_output=True, text=True) # noqa: S607
assert out.stdout.strip() == "", "grandchild survived: you killed the child, not the group"