hkuds--openharness
bf5931e7c1
Close API clients when the runtime shuts down to release HTTP connection pool resources, and surface the active session ID in /session output. Cherry-picked from PR #273. Excluded the embedded-wrapper session resolver and memory parser API changes because they need a narrower public API design.
33 行
817 B
Python
33 行
817 B
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from openharness.ui.runtime import build_runtime, close_runtime
|
|
|
|
|
|
class _ClosableApiClient:
|
|
def __init__(self) -> None:
|
|
self.closed = False
|
|
|
|
async def stream_message(self, request):
|
|
del request
|
|
if False:
|
|
yield None
|
|
|
|
async def close(self) -> None:
|
|
self.closed = True
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_close_runtime_closes_api_client(tmp_path: Path, monkeypatch):
|
|
monkeypatch.setenv("OPENHARNESS_CONFIG_DIR", str(tmp_path / "config"))
|
|
monkeypatch.setenv("OPENHARNESS_DATA_DIR", str(tmp_path / "data"))
|
|
client = _ClosableApiClient()
|
|
|
|
bundle = await build_runtime(cwd=str(tmp_path), api_client=client)
|
|
await close_runtime(bundle)
|
|
|
|
assert client.closed is True
|