test: add regression test for stale PID in gateway_state.json (#1631)
Verifies that write_runtime_status() overwrites pid and start_time from a previous process rather than preserving them via setdefault(). Covers the fix from PR #1632.
This commit is contained in:
parent
247e3c1470
commit
c16870277c
1 changed files with 20 additions and 0 deletions
|
|
@ -44,6 +44,26 @@ class TestGatewayPidState:
|
||||||
|
|
||||||
|
|
||||||
class TestGatewayRuntimeStatus:
|
class TestGatewayRuntimeStatus:
|
||||||
|
def test_write_runtime_status_overwrites_stale_pid_on_restart(self, tmp_path, monkeypatch):
|
||||||
|
"""Regression: setdefault() preserved stale PID from previous process (#1631)."""
|
||||||
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
||||||
|
|
||||||
|
# Simulate a previous gateway run that left a state file with a stale PID
|
||||||
|
state_path = tmp_path / "gateway_state.json"
|
||||||
|
state_path.write_text(json.dumps({
|
||||||
|
"pid": 99999,
|
||||||
|
"start_time": 1000.0,
|
||||||
|
"kind": "hermes-gateway",
|
||||||
|
"platforms": {},
|
||||||
|
"updated_at": "2025-01-01T00:00:00Z",
|
||||||
|
}))
|
||||||
|
|
||||||
|
status.write_runtime_status(gateway_state="running")
|
||||||
|
|
||||||
|
payload = status.read_runtime_status()
|
||||||
|
assert payload["pid"] == os.getpid(), "PID should be overwritten, not preserved via setdefault"
|
||||||
|
assert payload["start_time"] != 1000.0, "start_time should be overwritten on restart"
|
||||||
|
|
||||||
def test_write_runtime_status_records_platform_failure(self, tmp_path, monkeypatch):
|
def test_write_runtime_status_records_platform_failure(self, tmp_path, monkeypatch):
|
||||||
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue