Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion stackvox/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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")
7 changes: 6 additions & 1 deletion tests/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -347,6 +351,7 @@ def state(mocker, exit_wedged):
yield daemon_state
finally:
daemon_state.shutdown()
daemon_state.watchdog.join()


def _wait_until(condition, timeout: float = 1.0) -> None:
Expand Down
Loading