From 9421e211f129b4e2e5cbc0ef792ecf9648dac6d8 Mon Sep 17 00:00:00 2001 From: StuBehan Date: Tue, 27 Oct 2026 22:26:02 +0000 Subject: [PATCH 1/3] test: wait for the watchdog to stop between tests --- stackvox/daemon.py | 3 ++- tests/test_daemon.py | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/stackvox/daemon.py b/stackvox/daemon.py index 16db445..b323176 100644 --- a/stackvox/daemon.py +++ b/stackvox/daemon.py @@ -272,7 +272,8 @@ def __init__( self.deadline: float | None = None self.worker = threading.Thread(target=self._worker, daemon=True) self.worker.start() - threading.Thread(target=self._watchdog, daemon=True, name="stackvox-watchdog").start() + self.watchdog = threading.Thread(target=self._watchdog, daemon=True, name="stackvox-watchdog") + self.watchdog.start() _start_device_watcher() def _worker(self) -> None: diff --git a/tests/test_daemon.py b/tests/test_daemon.py index 5ee0fc0..35f7bfa 100644 --- a/tests/test_daemon.py +++ b/tests/test_daemon.py @@ -337,7 +337,11 @@ def exit_wedged(mocker): def state(mocker, exit_wedged): """A _DaemonState with the engine and the audio side mocked out, and a watchdog that polls fast enough to test. The poll interval is patched before - the watchdog starts, because its first wait reads it once.""" + the watchdog starts, because its first wait reads it once. + + Teardown waits for the watchdog to stop before the mocks are undone. A + watchdog paused between spotting an overrun and calling _exit_wedged would + otherwise wake in the next test and call its mock, or the real exit.""" mocker.patch.object(daemon, "WATCHDOG_POLL_SECONDS", 0.01) mocker.patch.object(daemon, "Stackvox") mocker.patch.object(daemon, "_refresh_audio_devices") @@ -347,6 +351,7 @@ def state(mocker, exit_wedged): yield daemon_state finally: daemon_state.shutdown() + daemon_state.watchdog.join(timeout=1.0) def _wait_until(condition, timeout: float = 1.0) -> None: From 568cae1a5ff195f901f81142216b8332ced87f84 Mon Sep 17 00:00:00 2001 From: StuBehan Date: Tue, 27 Oct 2026 22:37:25 +0000 Subject: [PATCH 2/3] test: join the watchdog without a timeout --- tests/test_daemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_daemon.py b/tests/test_daemon.py index 35f7bfa..7f45edc 100644 --- a/tests/test_daemon.py +++ b/tests/test_daemon.py @@ -351,7 +351,7 @@ def state(mocker, exit_wedged): yield daemon_state finally: daemon_state.shutdown() - daemon_state.watchdog.join(timeout=1.0) + daemon_state.watchdog.join() def _wait_until(condition, timeout: float = 1.0) -> None: From b15a655772ec69dcc3819099c3ad86f62ac97c53 Mon Sep 17 00:00:00 2001 From: StuBehan Date: Tue, 27 Oct 2026 22:37:25 +0000 Subject: [PATCH 3/3] test: keep the daemon's runtime files in tmp --- tests/conftest.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..7097a20 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +import pytest + +from stackvox import daemon + + +@pytest.fixture(autouse=True) +def isolated_runtime_files(mocker, tmp_path): + """Point the daemon's socket and pid files into the test's temp directory. + + The defaults are the live daemon's own files, and a stray real + `_exit_wedged` or startup during a test run would delete or replace them, + leaving a running daemon that no client can reach.""" + mocker.patch.object(daemon, "SOCKET_PATH", tmp_path / "daemon.sock") + mocker.patch.object(daemon, "PID_PATH", tmp_path / "daemon.pid")