Files
hermes-agent/tests/test_process_scan.py
Teknium 66b9174242 test: pin that a scan skips an exited child and finds the live one
A real unreaped child of the test process sits beside a live one; red with the skip removed
(ZombieProcess), green with it.
2026-11-19 01:09:04 -08:00

31 lines
917 B
Python

"""A child that exits while a test scans its parent's children is skipped, not raised on.
``tests/process_scan.py`` is what tests use to find a worker/supervisor child by command line.
"""
from __future__ import annotations
import os
import subprocess
import psutil
import pytest
from tests.process_scan import children_matching
from tests.waiting import wait_until
pytestmark = pytest.mark.platforms("posix")
def test_an_exited_unreaped_child_is_skipped_and_the_live_one_is_found():
exited = subprocess.Popen(["true"])
keeper = subprocess.Popen(["sleep", "30"])
try:
wait_until(lambda: psutil.Process(exited.pid).status() == psutil.STATUS_ZOMBIE, what="zombie child")
found = children_matching(os.getpid(), lambda p: p.cmdline()[:1] == ["sleep"])
assert [p.pid for p in found] == [keeper.pid]
finally:
keeper.kill()
keeper.wait()
exited.wait()