From 17bdb64ed6aef77ef8339a4082b8a9b7a55e8c88 Mon Sep 17 00:00:00 2001 From: Ovtcharov Date: Mon, 20 Jul 2026 16:55:14 -0700 Subject: [PATCH] test(daemon): de-flake sidecar stop test on the pid-liveness check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test_connection_stopped_after_running_raises_again used a fake manager that reports a hardcoded pid (4321) but owns no real OS process, so its shutdown() can't make that pid disappear. registry.stop() then verifies the pid is gone via psutil.pid_exists against the real process table — which spuriously raises StopFailedError whenever pid 4321 happens to be a live process on the runner (observed on macOS CI). Patch pid_exists to False for the fake so the liveness check reflects the double's intent (the fake sidecar is terminated) rather than the host's process table. Production behavior is unchanged — a real manager tree-kills its real pid, so the check stays meaningful there. --- tests/unit/test_daemon_relay.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_daemon_relay.py b/tests/unit/test_daemon_relay.py index 52bff9ac3..2a0cb848e 100644 --- a/tests/unit/test_daemon_relay.py +++ b/tests/unit/test_daemon_relay.py @@ -274,7 +274,16 @@ def test_connection_running_returns_base_url_and_bearer(): assert bearer == ensured["token"] -def test_connection_stopped_after_running_raises_again(): +def test_connection_stopped_after_running_raises_again(monkeypatch): + # The fake manager reports a hardcoded pid but owns no real OS process, so + # its shutdown() can't make that pid disappear. registry.stop() verifies the + # pid is gone via psutil.pid_exists against the real process table, which + # flakes when the fake pid collides with a live process on the runner. Model + # the fake sidecar as fully terminated so the check reflects the double's + # intent, not the host's process table. + monkeypatch.setattr( + "gaia.daemon.sidecars.registry.psutil.pid_exists", lambda pid: False + ) reg = _toy_registry() reg.ensure("toy") reg.stop("toy")