Prevent terminal auth spinner deadlock

This commit is contained in:
2569718930@qq.com
2026-06-01 12:36:29 +08:00
parent fb6c354317
commit 49cb0bb42d
5 changed files with 360 additions and 18 deletions
+37
View File
@@ -775,6 +775,43 @@ def test_city_detail_batch_chart_scope_returns_only_chart_fields(monkeypatch):
assert "ai_analysis" not in detail
def test_chart_detail_payload_avoids_threadpool_queue_and_reuses_short_cache(monkeypatch):
import asyncio
build_calls = 0
async def fail_threadpool(*_args, **_kwargs):
raise AssertionError("chart payload should not wait behind the shared threadpool")
def build_chart_detail(data, resolution):
nonlocal build_calls
build_calls += 1
return {
"city": data["city"],
"resolution": resolution,
"hourly": data["hourly"],
}
city_api._CITY_CHART_DETAIL_PAYLOAD_CACHE.clear()
city_api._CITY_CHART_DETAIL_PAYLOAD_CACHE_TS.clear()
monkeypatch.setenv("POLYWEATHER_CITY_DETAIL_PAYLOAD_CACHE_TTL_SEC", "20")
monkeypatch.setattr(city_api, "run_in_threadpool", fail_threadpool)
monkeypatch.setattr(city_api.legacy_routes, "_build_city_chart_detail_payload", build_chart_detail)
data = {
"city": "paris",
"updated_at": "2026-05-30T15:00:00Z",
"hourly": {"times": ["2026-05-30T15:00:00Z"], "temps": [20.0]},
}
first = asyncio.run(city_api._build_city_chart_detail_payload(data, "10m"))
second = asyncio.run(city_api._build_city_chart_detail_payload(data, "10m"))
assert first == second
assert first["resolution"] == "10m"
assert build_calls == 1
def test_city_detail_batch_endpoint_limits_backend_concurrency(monkeypatch):
import asyncio