Files
cleveragents-core/benchmarks/server_remote_project_bench.py
freemo 8e9aa7af48 fix(client): address server client chain review findings
- Promote _request() to public method request() in ServerHttpClient
  to fix encapsulation violation across sync_client and remote_project
- Fix WebSocket connect() to raise NotImplementedError with clear TODO
  documenting that real websockets transport is not yet implemented
- Fix thread safety: protect last_event_id write under self._lock
  in ws_client.process_event()
- Broaden exception handling in sync() to catch ServerTimeoutError
  and A2aNotAvailableError in addition to ServerConnectionError
- Add has_next to PageResult in benchmark and test helpers
- Add comments explaining Retry-After header logging-only behavior
  and why blocking time.sleep is acceptable in sync client
- Update all test steps, robot helpers, and benchmarks to use the
  renamed public request() method and updated connect() behavior

Refs: #335, #336, #337, #338
2026-03-24 20:28:19 +00:00

102 lines
2.2 KiB
Python

"""ASV benchmarks for Remote Project client."""
from __future__ import annotations
import importlib
import sys
from pathlib import Path
from unittest.mock import MagicMock
_SRC = str(Path(__file__).resolve().parents[1] / "src")
if _SRC not in sys.path:
sys.path.insert(0, _SRC)
import cleveragents # noqa: E402
importlib.reload(cleveragents)
from cleveragents.client.http_client import ( # noqa: E402
PageResult,
ServerHttpClient,
)
from cleveragents.client.remote_project import ( # noqa: E402
RemoteProject,
RemoteProjectClient,
)
_ITEMS = [
{"id": f"rp{i}", "name": f"proj-{i}", "alias": f"p{i}", "description": f"Proj {i}"}
for i in range(20)
]
def _build() -> RemoteProjectClient:
mock = MagicMock(spec=ServerHttpClient)
mock.list_endpoint.return_value = PageResult(
items=_ITEMS, page=1, per_page=50, total=20, has_next=False
)
return RemoteProjectClient(mock)
class ListProjectsSuite:
"""Benchmark project listing."""
timeout = 60
def setup(self) -> None:
self.client = _build()
def time_list_cold(self) -> None:
c = _build()
c.list_projects()
def time_list_cached(self) -> None:
self.client.list_projects()
class ResolveProjectSuite:
"""Benchmark project resolution."""
timeout = 60
def setup(self) -> None:
self.client = _build()
self.client.list_projects()
def time_resolve_by_name(self) -> None:
self.client.get_project("proj-10")
def time_resolve_by_alias(self) -> None:
self.client.get_project("p10")
class CacheSuite:
"""Benchmark cache operations."""
timeout = 60
def time_invalidate_all(self) -> None:
c = _build()
c.list_projects()
c.invalidate_cache()
def time_invalidate_ns(self) -> None:
c = _build()
c.list_projects()
c.invalidate_cache("default")
class RemoteProjectCreationSuite:
"""Benchmark RemoteProject creation."""
timeout = 60
def time_create(self) -> None:
RemoteProject(
project_id="rp1",
name="test",
namespace="default",
alias="t",
description="Test project",
)