okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ffb3d9b31
main
1"""Without /proc (macOS) an ended child that is not reaped yet (a zombie) is not "running" (lane 8 on a real Mac: a finished strata_install read as running). 2Runs on Linux too: the /proc branch is switched off, so the ps branch (the one a Mac takes) is what decides.""" 3from __future__import annotations 4 5import subprocess 6import sys 7import time 8import unittest 9from pathlib import Path 10from unittest import mock 11 12ROOT = Path (__file__ ).resolve ().parents [1 ] 13sys .path .insert (0 ,str (ROOT )) 14sys .path .insert (0 ,str (ROOT / "tools" )) 15import strata_mcp # noqa: E402 16 17 18@ unittest . skipIf ( strata_mcp . WIN , "POSIX process states" ) 19class ZombieWithoutProc (unittest .TestCase ): 20def test_an_ended_unreaped_child_is_not_running (self ): 21child = subprocess .Popen ([sys .executable ,"-c" ,"pass" ]) 22try : 23time .sleep (1.0 )# it has ended; nobody has waited for it, so it is a zombie now 24with mock .patch .object (strata_mcp ,"_has_proc" ,return_value = False ): 25self .assertIsNone (strata_mcp .proc_identity (child .pid )) 26self .assertFalse (strata_mcp .proc_alive (child .pid ,"pid" )) 27finally : 28child .wait () 29 30def test_a_running_child_is_running_and_a_gone_one_is_not (self ): 31child = subprocess .Popen ([sys .executable ,"-c" ,"import time; time.sleep(30)" ]) 32try : 33with mock .patch .object (strata_mcp ,"_has_proc" ,return_value = False ): 34self .assertEqual (strata_mcp .proc_identity (child .pid ),"pid" ) 35finally : 36child .kill () 37child .wait () 38with mock .patch .object (strata_mcp ,"_has_proc" ,return_value = False ): 39self .assertIsNone (strata_mcp .proc_identity (child .pid )) 40 41def test_without_ps_the_old_check_stays (self ): 42with mock .patch .object (strata_mcp ,"_has_proc" ,return_value = False ),mock .patch .object (strata_mcp ,"_ps_state" ,return_value = None ): 43self .assertEqual (strata_mcp .proc_identity (strata_mcp .os .getpid ()),"pid" ) 44 45 46if __name__ == "__main__" : 47unittest .main ()