Restart under high swap after unloading resident Ollama models

This commit is contained in:
Andrew Emelyaneko
2026-10-31 21:59:18 +03:00
parent 961efd9b40
commit d2415425fc
2 changed files with 29 additions and 27 deletions
+14 -4
View File
@@ -37,15 +37,15 @@ def test_check_once_restarts_when_threshold_exceeded(tmp_path):
assert result["restarted"] is True
def test_check_once_defers_when_busy(tmp_path):
def test_check_once_restarts_under_load(tmp_path):
config = make_config(tmp_path)
runtime = a.Runtime(config)
fake_stats = c.SwapStats(100, 40, 60)
with mock.patch.object(runtime.sampler, "sample", return_value=fake_stats), \
mock.patch.object(a.RemoteOllama, "is_busy", return_value=True):
mock.patch.object(a.RemoteOllama, "is_busy", return_value=True), \
mock.patch.object(runtime.controller, "restart", return_value={"restarted": True}):
result = runtime.check_once()
assert result["restarted"] is False
assert result["deferred"] is True
assert result["restarted"] is True
def test_restart_rejects_busy_without_force(tmp_path):
@@ -104,3 +104,13 @@ def test_http_status_and_restart(tmp_path):
assert data["ok"] is True
httpd.shutdown()
httpd.server_close()
def test_state_store_mutate_persists(tmp_path):
state_path = tmp_path / "state.json"
store = a.StateStore(str(state_path))
assert store.mutate(lambda data: {**data, "last_restart": "2026-10-31T20:00:00+00:00"})[
"last_restart"
] == "2026-10-31T20:00:00+00:00"
reloaded = a.StateStore(str(state_path))
assert reloaded.snapshot()["last_restart"] == "2026-10-31T20:00:00+00:00"