mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-09-14 11:06:13 +05:00
Treat zombie test processes as exited
This commit is contained in:
parent
9b85d82a62
commit
1106b84d99
@ -577,12 +577,11 @@ def wait_for_process(predicate: Callable[[psutil.Process, str], bool], *, timeou
|
||||
|
||||
def pid_is_alive(pid: int) -> bool:
|
||||
try:
|
||||
os.kill(pid, 0)
|
||||
except ProcessLookupError:
|
||||
return psutil.Process(pid).status() != psutil.STATUS_ZOMBIE
|
||||
except (psutil.NoSuchProcess, psutil.ZombieProcess):
|
||||
return False
|
||||
except PermissionError:
|
||||
except psutil.AccessDenied:
|
||||
return True
|
||||
return True
|
||||
|
||||
|
||||
def wait_for_pid_to_disappear(pid: int, *, timeout: float = 20.0) -> None:
|
||||
|
||||
@ -10,6 +10,7 @@ import time
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import psutil
|
||||
|
||||
from archivebox.core.models import ArchiveResult, Snapshot
|
||||
from archivebox.crawls.models import Crawl
|
||||
@ -38,6 +39,19 @@ from archivebox.tests.test_orm_helpers import use_archivebox_db
|
||||
pytestmark = pytest.mark.django_db(transaction=True)
|
||||
|
||||
|
||||
def test_pid_is_alive_treats_unreaped_zombie_as_exited():
|
||||
proc = subprocess.Popen([sys.executable, "-c", "pass"])
|
||||
try:
|
||||
deadline = time.time() + 5
|
||||
while time.time() < deadline and psutil.Process(proc.pid).status() != psutil.STATUS_ZOMBIE:
|
||||
time.sleep(0.01)
|
||||
|
||||
assert psutil.Process(proc.pid).status() == psutil.STATUS_ZOMBIE
|
||||
assert not pid_is_alive(proc.pid)
|
||||
finally:
|
||||
proc.wait(timeout=5)
|
||||
|
||||
|
||||
def _require_sonic_binary() -> None:
|
||||
assert shutil.which("sonic") is not None, "sonic server binary is required for Sonic worker takeover tests"
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user