fix(gateway): FabriX 가 맞는 인증 조합에도 간헐 401 — 4개 조합 뒤 유력 조합 1초 쉬고 한 번 더

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
lee-hyeon-cheol
2026-09-21 19:41:41 +09:00
co-authored by Claude Fable 5.1
parent 9bd0849f27
commit b08afa389a
2 changed files with 29 additions and 0 deletions
+20
View File
@@ -126,6 +126,26 @@ async def test_401_retries_other_auth_shape_and_remembers(upstream):
assert len(calls) == n + 1 and calls[-1].headers["x-openapi-token"] == "Bearer tok"
@override_settings(FABRIX_ENV=FULL_ENV)
async def test_flaky_401_on_right_auth_is_retried_once(upstream, monkeypatch):
"""FabriX 가 맞는 조합에도 가끔 401 — 4개 다 돈 뒤 맨 앞 조합 한 번 더."""
from apps.gateway import views
monkeypatch.setattr(views, "RETRY_PAUSE_S", 0)
hits = {"n": 0}
def handler(req: httpx.Request) -> httpx.Response:
hits["n"] += 1
if hits["n"] <= 4:
return httpx.Response(401, content=b"flaky")
return httpx.Response(200, json={"choices": []})
calls = upstream(handler)
resp = await _post({"messages": []})
assert resp.status_code == 200 and len(calls) == 5
assert calls[0].headers.get("x-openapi-token") == calls[4].headers.get("x-openapi-token")
@override_settings(FABRIX_ENV=FULL_ENV)
async def test_stream_upstream_error_becomes_sse_error(upstream):
upstream(lambda r: _sse(b"boom", 500))