fix: align PID-Sentinel tests with gateway_pid detection_source

Mock _check_gateway_pid_alive=False in 7 tests that test secondary/
tertiary/quaternary detection paths, since the PID-Sentinel (PRIMARY)
now always returns True under pytest (parent process exists).

Production-Impact: none (test-only change)
This commit is contained in:
Bernd (Hermes)
2026-08-01 21:14:31 +02:00
parent 2ef44fec9c
commit 2a7fade341
+13 -6
View File
@@ -1362,7 +1362,8 @@ class TestDetectionTimerPgrepSelfExclude:
own_pid = os.getpid() own_pid = os.getpid()
# Mock subprocess.run: pgrep returns only our own PID # Mock subprocess.run: pgrep returns only our own PID
with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run: with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run, \
patch.object(DetectionTimer, '_check_gateway_pid_alive', return_value=False):
mock_run.return_value = MagicMock( mock_run.return_value = MagicMock(
stdout=f"{own_pid}\n", stdout=f"{own_pid}\n",
stderr="", stderr="",
@@ -1425,7 +1426,8 @@ class TestDetectionTimerOnChangeCallback:
MagicMock(stdout=f"{own_pid}\n", stderr="", returncode=0), MagicMock(stdout=f"{own_pid}\n", stderr="", returncode=0),
] ]
with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run: with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run, \
patch.object(DetectionTimer, '_check_gateway_pid_alive', return_value=False):
mock_run.side_effect = mock_results mock_run.side_effect = mock_results
dt = DetectionTimer( dt = DetectionTimer(
@@ -2088,7 +2090,8 @@ class TestDetectionTimerPluginState:
}) })
own_pid = os.getpid() own_pid = os.getpid()
with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run: with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run, \
patch.object(DetectionTimer, '_check_gateway_pid_alive', return_value=False):
mock_run.return_value = MagicMock( mock_run.return_value = MagicMock(
stdout=f"{own_pid}\n", stdout=f"{own_pid}\n",
stderr="", stderr="",
@@ -2215,6 +2218,7 @@ class TestDetectionSourceTelemetry:
detection_interval=0.1, detection_interval=0.1,
plugin_state_path=state_path, plugin_state_path=state_path,
) )
with patch.object(DetectionTimer, '_check_gateway_pid_alive', return_value=False):
dt.check() dt.check()
assert routing_telemetry.heartbeat_detection_source == "plugin_state" assert routing_telemetry.heartbeat_detection_source == "plugin_state"
@@ -2226,7 +2230,8 @@ class TestDetectionSourceTelemetry:
routing_telemetry.heartbeat_detection_source = "none" routing_telemetry.heartbeat_detection_source = "none"
own_pid = os.getpid() own_pid = os.getpid()
with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run: with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run, \
patch.object(DetectionTimer, '_check_gateway_pid_alive', return_value=False):
mock_run.return_value = MagicMock( mock_run.return_value = MagicMock(
stdout=f"{own_pid}\n", stdout=f"{own_pid}\n",
stderr="", stderr="",
@@ -2248,7 +2253,8 @@ class TestDetectionSourceTelemetry:
routing_telemetry.heartbeat_detection_source = "none" routing_telemetry.heartbeat_detection_source = "none"
own_pid = os.getpid() own_pid = os.getpid()
with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run: with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run, \
patch.object(DetectionTimer, '_check_gateway_pid_alive', return_value=False):
mock_run.return_value = MagicMock( mock_run.return_value = MagicMock(
stdout=f"{own_pid}\n99999\n", stdout=f"{own_pid}\n99999\n",
stderr="", stderr="",
@@ -2276,7 +2282,8 @@ class TestDetectionSourceTelemetry:
gw_path = f.name gw_path = f.name
try: try:
with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run: with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run, \
patch.object(DetectionTimer, '_check_gateway_pid_alive', return_value=False):
dt = DetectionTimer( dt = DetectionTimer(
gateway_state_path=gw_path, gateway_state_path=gw_path,
detection_interval=0.1, detection_interval=0.1,