fix(api): stop serve cleanly with jobs, streams and remote sessions open

This commit is contained in:
imSp4rky
2026-11-28 21:11:50 -07:00
parent f5c8858e6e
commit 7713f8df3f
13 changed files with 222 additions and 45 deletions
+24
View File
@@ -175,6 +175,30 @@ async def test_events_burst_mode(aiohttp_client, dashboard_cfg) -> None:
assert [e["data"]["action"] for e in body["events"] if e["event"] == "session"] == ["create", "delete"]
def test_bus_close_ends_a_full_subscriber_queue() -> None:
local = EventBus()
queue: asyncio.Queue = asyncio.Queue(maxsize=1)
local._subs.append(queue)
local.publish("session", {"action": "create"})
local.close()
assert queue.get_nowait() is None
async def test_the_event_stream_ends_at_serve_shutdown(aiohttp_client, dashboard_cfg) -> None:
from unshackle.core.api.download_manager import shutdown_download_manager
from unshackle.core.api.events import close_event_streams
app = make_app()
assert {close_event_streams, shutdown_download_manager} <= set(app.on_shutdown)
client = await aiohttp_client(app)
resp = await client.get("/api/dashboard/events", headers={"X-Secret-Key": "dash-secret"})
assert resp.status == 200
await asyncio.wait_for(resp.content.readuntil(b"\n\n"), timeout=10)
await close_event_streams(app)
await asyncio.wait_for(resp.content.read(), timeout=10)
assert resp.content.at_eof()
async def test_session_action_log() -> None:
store = SessionStore()
entry = await store.create("EXAMPLE", object(), owner_key="k")