test(evaluation): shorten deadline cancellation wait

This commit is contained in:
2026-10-12 22:32:39 +03:00
parent fe76faa11c
commit 045ef01adf

View File

@@ -4,7 +4,7 @@
import asyncio
import copy
import json
from time import monotonic
from types import SimpleNamespace
from uuid import uuid4
import httpx
@@ -173,14 +173,29 @@ def test_token_input_budget_refuses_excess_without_http(runtime_source):
assert runtime_source.db.query(CapacityLease).filter_by(run_id=runtime_source.run.id).count() == 0
def test_whole_recipe_deadline_cancels_stalled_provider_and_releases_lease(runtime_source):
def test_whole_recipe_deadline_cancels_stalled_provider_and_releases_lease(runtime_source, monkeypatch):
from src.services.dashboard_testing.execution import evaluation_text_transport
runtime_source.transport_state["delay"] = 40
started = monotonic()
configured_deadlines = []
actual_wait_for = asyncio.wait_for
async def wait_for_with_test_deadline(awaitable, *, timeout):
configured_deadlines.append(timeout)
return await actual_wait_for(awaitable, timeout=0.05)
# Keep the recipe's configured 30s boundary; scale only the test's elapsed wait.
monkeypatch.setattr(
evaluation_text_transport,
"asyncio",
SimpleNamespace(wait_for=wait_for_with_test_deadline),
)
with pytest.raises(RuntimeError, match="^EVALUATION_TIMED_OUT$"):
invoke(runtime_source)
elapsed = monotonic() - started
assert 29 <= elapsed < 35
assert configured_deadlines == [30]
assert runtime_source.transport_state["cancelled"] is True
assert len(runtime_source.requests) == 1
_payload, timeout = runtime_source.requests[0]
assert timeout["read"] == 30 and timeout["connect"] == 30
assert runtime_source.db.query(CapacityLease).filter_by(run_id=runtime_source.run.id, status="claimed").count() == 0
# #endregion Test.EvaluationText.SubmitRuntime