8e9aa7af48
- 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
88 lines
2.2 KiB
Python
88 lines
2.2 KiB
Python
"""ASV benchmarks for Plan Sync client."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
import sys
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock
|
|
|
|
import httpx
|
|
|
|
_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 ServerHttpClient # noqa: E402
|
|
from cleveragents.client.sync_client import ( # noqa: E402
|
|
ExecutionResult,
|
|
PlanSyncClient,
|
|
SyncScope,
|
|
SyncSummary,
|
|
)
|
|
|
|
|
|
def _mock_response(status: int = 200, body: dict | None = None) -> httpx.Response:
|
|
return httpx.Response(
|
|
status_code=status,
|
|
json=body,
|
|
headers={},
|
|
request=httpx.Request("GET", "http://mock"),
|
|
)
|
|
|
|
|
|
class SyncScopeSuite:
|
|
"""Benchmark SyncScope operations."""
|
|
|
|
timeout = 60
|
|
|
|
def time_active_types_all(self) -> None:
|
|
SyncScope().active_types()
|
|
|
|
def time_active_types_partial(self) -> None:
|
|
SyncScope(actions=True, skills=False, tools=True, projects=False).active_types()
|
|
|
|
|
|
class SyncOperationSuite:
|
|
"""Benchmark sync operations."""
|
|
|
|
timeout = 60
|
|
|
|
def setup(self) -> None:
|
|
self.mock_http = MagicMock(spec=ServerHttpClient)
|
|
self.mock_http.request.return_value = _mock_response(200, {"id": "srv"})
|
|
self.client = PlanSyncClient(self.mock_http)
|
|
self.items = [{"id": f"item-{i}"} for i in range(10)]
|
|
|
|
def time_sync_10_items(self) -> None:
|
|
self.client.sync(self.items, "actions")
|
|
|
|
def time_sync_dry_run(self) -> None:
|
|
self.client.sync(self.items, "actions", dry_run=True)
|
|
|
|
|
|
class SyncSummarySuite:
|
|
"""Benchmark SyncSummary creation."""
|
|
|
|
timeout = 60
|
|
|
|
def time_summary_creation(self) -> None:
|
|
SyncSummary(created=5, updated=3, skipped=1, errors=0)
|
|
|
|
def time_total_processed(self) -> None:
|
|
s = SyncSummary(created=5, updated=3, skipped=1, errors=1)
|
|
_ = s.total_processed
|
|
|
|
|
|
class ExecutionResultSuite:
|
|
"""Benchmark ExecutionResult creation."""
|
|
|
|
timeout = 60
|
|
|
|
def time_create_result(self) -> None:
|
|
ExecutionResult(plan_id="p1", server_plan_id="sp1", status="done", message="ok")
|