feat(host-agent): report assignment outcomes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
from datetime import UTC, datetime
|
||||
|
||||
import httpx
|
||||
@@ -131,3 +132,37 @@ def test_stale_lease_response_raises_typed_error_without_retry() -> None:
|
||||
|
||||
asyncio.run(scenario())
|
||||
assert attempts == 1
|
||||
|
||||
|
||||
def test_result_report_retries_identical_payload_after_response_loss() -> None:
|
||||
payloads: list[dict[str, object]] = []
|
||||
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
payloads.append(json.loads(request.content))
|
||||
if len(payloads) == 1:
|
||||
raise httpx.ReadError("response lost", request=request)
|
||||
return httpx.Response(200, json={"status": "already_recorded"})
|
||||
|
||||
async def scenario() -> None:
|
||||
async with httpx.AsyncClient(
|
||||
transport=httpx.MockTransport(handler),
|
||||
base_url="https://control.example",
|
||||
) as http_client:
|
||||
client = HostAgentClient(
|
||||
_config(),
|
||||
http_client=http_client,
|
||||
sleep=lambda delay: asyncio.sleep(0),
|
||||
)
|
||||
response = await client.report_result(
|
||||
_assignment(),
|
||||
status="failed",
|
||||
failure_reason="planner unavailable",
|
||||
result={"runtime_status": "failed"},
|
||||
)
|
||||
|
||||
assert response.status == "already_recorded"
|
||||
|
||||
asyncio.run(scenario())
|
||||
assert len(payloads) == 2
|
||||
assert payloads[0] == payloads[1]
|
||||
assert payloads[0]["failure_reason"] == "planner unavailable"
|
||||
|
||||
Reference in New Issue
Block a user