feat: 保存并登记当前 Client (#11)
This commit is contained in:
@@ -60,14 +60,46 @@ class MockAdminGatewayContractTest(unittest.TestCase):
|
||||
"reported_at": "2026-08-06T08:03:00Z",
|
||||
}
|
||||
|
||||
def test_gateway_has_only_three_business_methods(self):
|
||||
def test_gateway_has_only_four_business_methods(self):
|
||||
self.assertEqual(
|
||||
AdminGateway.__abstractmethods__,
|
||||
{"claim_next", "submit_result", "submit_failure"},
|
||||
{
|
||||
"register_client",
|
||||
"claim_next",
|
||||
"submit_result",
|
||||
"submit_failure",
|
||||
},
|
||||
)
|
||||
for forbidden in ("get_status", "heartbeat", "renew_lease"):
|
||||
self.assertFalse(hasattr(AdminGateway, forbidden))
|
||||
|
||||
def test_registration_is_idempotent_and_keeps_latest_profile(self):
|
||||
first = self.gateway.register_client(
|
||||
ClientInfo("client-001", "办公室电脑"), self.all_capabilities
|
||||
)
|
||||
second = self.gateway.register_client(
|
||||
ClientInfo("client-001", "仓库电脑"), self.all_capabilities
|
||||
)
|
||||
|
||||
self.assertTrue(first.registered)
|
||||
self.assertEqual(second.client_id, "client-001")
|
||||
self.assertEqual(self.gateway.registration_count, 1)
|
||||
saved_client, saved_capabilities = self.gateway.registered_client(
|
||||
"client-001"
|
||||
)
|
||||
self.assertEqual(saved_client.name, "仓库电脑")
|
||||
self.assertEqual(saved_capabilities, self.all_capabilities)
|
||||
|
||||
def test_registration_can_simulate_admin_failure(self):
|
||||
self.gateway.fail_next_call_temporarily()
|
||||
|
||||
with self.assertRaises(AdminGatewayError) as context:
|
||||
self.gateway.register_client(self.client, self.all_capabilities)
|
||||
|
||||
self.assertEqual(context.exception.code, "ADMIN_UNAVAILABLE")
|
||||
self.assertTrue(context.exception.retryable)
|
||||
self.assertEqual(self.gateway.registration_count, 0)
|
||||
|
||||
def test_claim_returns_none_when_no_task_exists(self):
|
||||
self.assertIsNone(
|
||||
self.gateway.claim_next(self.client, self.all_capabilities)
|
||||
|
||||
Reference in New Issue
Block a user