| 123456789101112131415161718192021222324252627 |
- """PID 存活检测:死进程的 running run 应判为 interrupted,绝不误杀真实运行中的 run。"""
- import os
- from content_agent.dashboard_service import _process_alive
- def test_current_process_is_alive():
- assert _process_alive(os.getpid(), None) is True
- def test_nonexistent_pid_is_dead():
- assert _process_alive(999999, None) is False
- def test_unknown_pid_not_flagged():
- # 取不到/解析不了 pid 时,宁可显示运行中也不误判。
- assert _process_alive(None, None) is True
- assert _process_alive("not-an-int", None) is True
- def test_pid_reuse_detected_via_start_time():
- # 仅 Linux 有 /proc:活进程但启动时刻对不上 → 视为 PID 被复用 → 判死。
- if not os.path.exists(f"/proc/{os.getpid()}/stat"):
- return
- assert _process_alive(os.getpid(), "0") is False
- assert _process_alive(os.getpid(), None) is True
|