fix: preserve live tasks during daemon recovery
This commit is contained in:
1 parent
079d7b1e28
commit
0355af7833
11 files changed
+327
-17
No files matched your search
@@ -93,6 +93,7 @@ def test_ensure_daemon_running_standalone_override(monkeypatch):
|
||||
def test_ensure_daemon_running_auto_spawns():
|
||||
with (
|
||||
patch("artemis.runtime.daemon_client.is_daemon_running", side_effect=[False, True]),
|
||||
patch("artemis.runtime.daemon_client.is_port_in_use", return_value=False),
|
||||
patch("artemis.runtime.daemon_client.spawn_daemon") as mock_spawn,
|
||||
):
|
||||
ok, base_url = ensure_daemon_running(timeout=1.0, wait_ready=True)
|
||||
@@ -101,6 +102,42 @@ def test_ensure_daemon_running_auto_spawns():
|
||||
mock_spawn.assert_called_once()
|
||||
|
||||
|
||||
def test_busy_live_daemon_is_reused_without_spawning():
|
||||
with (
|
||||
patch("artemis.runtime.daemon_client.is_daemon_running", return_value=False),
|
||||
patch("artemis.runtime.daemon_client.is_port_in_use", return_value=True),
|
||||
patch(
|
||||
"artemis.runtime.daemon_client.read_server_info",
|
||||
return_value={"host": "127.0.0.1", "port": 8000, "pid": 12345},
|
||||
),
|
||||
patch("artemis.runtime.daemon_client.pid_is_alive", return_value=True),
|
||||
patch("artemis.runtime.daemon_client.spawn_daemon") as spawn,
|
||||
):
|
||||
assert ensure_daemon_running() == (True, "http://127.0.0.1:8000")
|
||||
spawn.assert_not_called()
|
||||
|
||||
|
||||
def test_unknown_port_owner_is_not_overwritten():
|
||||
with (
|
||||
patch("artemis.runtime.daemon_client.is_daemon_running", return_value=False),
|
||||
patch("artemis.runtime.daemon_client.is_port_in_use", return_value=True),
|
||||
patch("artemis.runtime.daemon_client.read_server_info", return_value=None),
|
||||
patch("artemis.runtime.daemon_client.spawn_daemon") as spawn,
|
||||
):
|
||||
assert ensure_daemon_running() == (False, None)
|
||||
spawn.assert_not_called()
|
||||
|
||||
|
||||
def test_liveness_probe_uses_lightweight_endpoint_and_configured_timeout(monkeypatch):
|
||||
from artemis.config.settings import settings
|
||||
|
||||
monkeypatch.setattr(settings, "ARTEMIS_DAEMON_PROBE_TIMEOUT_SECONDS", 7.0)
|
||||
with patch("urllib.request.urlopen", return_value=_daemon_ok_response(b"{}")) as probe:
|
||||
assert is_daemon_running()
|
||||
assert probe.call_args.args[0].full_url.endswith("/api/system/server-status")
|
||||
assert probe.call_args.kwargs["timeout"] == 7.0
|
||||
|
||||
|
||||
def test_submit_task_to_daemon():
|
||||
mock_resp = MagicMock()
|
||||
mock_resp.status = 200
|
||||
|
||||
Reference in new issue
Block a user