Files
hermes-agent/tests/hermes_cli/test_web_logs_async.py
Xipong fe9a5ccafa fix: offload dashboard log reads from event loop
(cherry picked from commit 6a41c1a3bb66b409625df9204362d64258bee36d)
2026-09-23 21:30:08 +05:30

27 lines
845 B
Python

import asyncio
import threading
from hermes_cli.web_routers import status
def test_get_logs_yields_while_reading_and_filtering(tmp_path, monkeypatch):
logs_dir = tmp_path / "logs"
logs_dir.mkdir()
(logs_dir / "agent.log").write_text("fixture\n", encoding="utf-8")
monkeypatch.setattr(status, "get_hermes_home", lambda: tmp_path)
loop_ran = threading.Event()
def blocking_read(*args, **kwargs):
assert loop_ran.wait(2), "log reading blocked the event loop"
return ["fixture"]
import hermes_cli.logs
monkeypatch.setattr(hermes_cli.logs, "_read_tail", blocking_read)
async def exercise():
asyncio.get_running_loop().call_soon(loop_ran.set)
return await status.get_logs(file="agent", lines=100)
assert asyncio.run(exercise()) == {"file": "agent", "lines": ["fixture"]}