diff --git a/tests/hermes_cli/test_gateway_service.py b/tests/hermes_cli/test_gateway_service.py index f2bfa8b870c1..c33c663d3691 100644 --- a/tests/hermes_cli/test_gateway_service.py +++ b/tests/hermes_cli/test_gateway_service.py @@ -108,6 +108,14 @@ def fake_run(cmd, check=True, **kwargs): class TestGeneratedSystemdUnits: + @staticmethod + def _expected_timeout_stop_sec() -> int: + """Mirror the formula in ``hermes_cli.gateway`` so this test stays + green when ``agent.restart_drain_timeout`` (and therefore the + derived TimeoutStopSec headroom) shifts in the shared defaults.""" + drain = int(gateway_cli._get_restart_drain_timeout() or 0) + return max(60, drain) + 30 + def test_user_unit_avoids_recursive_execstop_and_uses_extended_stop_timeout(self): unit = gateway_cli.generate_systemd_unit(system=False) @@ -115,10 +123,13 @@ def test_user_unit_avoids_recursive_execstop_and_uses_extended_stop_timeout(self assert "ExecStop=" not in unit assert "ExecReload=/bin/kill -USR1 $MAINPID" in unit assert f"RestartForceExitStatus={GATEWAY_SERVICE_RESTART_EXIT_CODE}" in unit - # TimeoutStopSec must exceed the default drain_timeout (60s) so - # systemd doesn't SIGKILL the cgroup before post-interrupt cleanup - # (tool subprocess kill, adapter disconnect) runs — issue #8202. - assert "TimeoutStopSec=90" in unit + # TimeoutStopSec must exceed the configured drain_timeout so systemd + # doesn't SIGKILL the cgroup before post-interrupt cleanup (tool + # subprocess kill, adapter disconnect) runs — issue #8202. Compute + # the expected value from the same helper the unit generator uses, + # so the assertion follows the configured default rather than + # hardcoding a stale value. + assert f"TimeoutStopSec={self._expected_timeout_stop_sec()}" in unit def test_user_unit_includes_resolved_node_directory_in_path(self, monkeypatch): monkeypatch.setattr(gateway_cli.shutil, "which", lambda cmd: "/home/test/.nvm/versions/node/v24.14.0/bin/node" if cmd == "node" else None) @@ -134,10 +145,11 @@ def test_system_unit_avoids_recursive_execstop_and_uses_extended_stop_timeout(se assert "ExecStop=" not in unit assert "ExecReload=/bin/kill -USR1 $MAINPID" in unit assert f"RestartForceExitStatus={GATEWAY_SERVICE_RESTART_EXIT_CODE}" in unit - # TimeoutStopSec must exceed the default drain_timeout (60s) so - # systemd doesn't SIGKILL the cgroup before post-interrupt cleanup - # (tool subprocess kill, adapter disconnect) runs — issue #8202. - assert "TimeoutStopSec=90" in unit + # TimeoutStopSec must exceed the configured drain_timeout so systemd + # doesn't SIGKILL the cgroup before post-interrupt cleanup (tool + # subprocess kill, adapter disconnect) runs — issue #8202. See + # ``_expected_timeout_stop_sec`` above for why this is computed. + assert f"TimeoutStopSec={self._expected_timeout_stop_sec()}" in unit assert "WantedBy=multi-user.target" in unit