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:
@@ -1362,7 +1362,8 @@ class TestDetectionTimerPgrepSelfExclude:
|
||||
own_pid = os.getpid()
|
||||
|
||||
# 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(
|
||||
stdout=f"{own_pid}\n",
|
||||
stderr="",
|
||||
@@ -1425,7 +1426,8 @@ class TestDetectionTimerOnChangeCallback:
|
||||
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
|
||||
|
||||
dt = DetectionTimer(
|
||||
@@ -2088,7 +2090,8 @@ class TestDetectionTimerPluginState:
|
||||
})
|
||||
|
||||
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(
|
||||
stdout=f"{own_pid}\n",
|
||||
stderr="",
|
||||
@@ -2215,6 +2218,7 @@ class TestDetectionSourceTelemetry:
|
||||
detection_interval=0.1,
|
||||
plugin_state_path=state_path,
|
||||
)
|
||||
with patch.object(DetectionTimer, '_check_gateway_pid_alive', return_value=False):
|
||||
dt.check()
|
||||
assert routing_telemetry.heartbeat_detection_source == "plugin_state"
|
||||
|
||||
@@ -2226,7 +2230,8 @@ class TestDetectionSourceTelemetry:
|
||||
routing_telemetry.heartbeat_detection_source = "none"
|
||||
|
||||
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(
|
||||
stdout=f"{own_pid}\n",
|
||||
stderr="",
|
||||
@@ -2248,7 +2253,8 @@ class TestDetectionSourceTelemetry:
|
||||
routing_telemetry.heartbeat_detection_source = "none"
|
||||
|
||||
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(
|
||||
stdout=f"{own_pid}\n99999\n",
|
||||
stderr="",
|
||||
@@ -2276,7 +2282,8 @@ class TestDetectionSourceTelemetry:
|
||||
gw_path = f.name
|
||||
|
||||
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(
|
||||
gateway_state_path=gw_path,
|
||||
detection_interval=0.1,
|
||||
|
||||
Reference in New Issue
Block a user