feat: 保存并登记当前 Client (#11)
This commit is contained in:
@@ -15,6 +15,7 @@ from .admin_gateway import (
|
||||
AdminTask,
|
||||
ClaimCapabilities,
|
||||
ClientInfo,
|
||||
RegistrationReceipt,
|
||||
SubmissionReceipt,
|
||||
)
|
||||
|
||||
@@ -49,8 +50,41 @@ class MockAdminGateway(AdminGateway):
|
||||
] = {}
|
||||
self._next_error: Optional[AdminGatewayError] = None
|
||||
self._reject_next_submission = False
|
||||
self._registrations: Dict[str, Tuple[ClientInfo, ClaimCapabilities]] = {}
|
||||
self._lock = Lock()
|
||||
|
||||
def register_client(
|
||||
self, client: ClientInfo, capabilities: ClaimCapabilities
|
||||
) -> RegistrationReceipt:
|
||||
"""幂等登记 Client,并保留最后一次上报内容供测试检查。"""
|
||||
|
||||
with self._lock:
|
||||
self._raise_forced_error()
|
||||
normalized = ClientInfo(client.client_id.strip(), client.name.strip())
|
||||
self._registrations[normalized.client_id] = (
|
||||
normalized,
|
||||
deepcopy(capabilities),
|
||||
)
|
||||
return RegistrationReceipt(
|
||||
registered=True,
|
||||
client_id=normalized.client_id,
|
||||
registered_at=utc_now_iso(),
|
||||
)
|
||||
|
||||
@property
|
||||
def registration_count(self) -> int:
|
||||
"""返回不同 Client ID 的登记数量。"""
|
||||
|
||||
return len(self._registrations)
|
||||
|
||||
def registered_client(
|
||||
self, client_id: str
|
||||
) -> Optional[Tuple[ClientInfo, ClaimCapabilities]]:
|
||||
"""测试辅助:返回某个 Client 最后一次登记的资料。"""
|
||||
|
||||
value = self._registrations.get(client_id)
|
||||
return deepcopy(value) if value is not None else None
|
||||
|
||||
def enqueue_task(self, task: AdminTask, assigned_client_id: str) -> None:
|
||||
"""测试辅助:加入一条分配给指定 Client 的任务。"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user