style: run the formatter over the issue 14 changes
ruff format only; no semantic change.
This commit is contained in:
@@ -327,9 +327,7 @@ class GatewaySettings:
|
||||
backpressure=_load_backpressure(scope_u, env),
|
||||
selector=_load_choice(env, f"{scope_u}__SELECTOR", _SELECTORS, "health_aware"),
|
||||
quota_full=_load_choice(env, f"{scope_u}__QUOTA_FULL", _QUOTA_FULL, "wait"),
|
||||
circuit_open=_load_choice(
|
||||
env, f"{scope_u}__CIRCUIT_OPEN", _CIRCUIT_OPEN, "fail_fast"
|
||||
),
|
||||
circuit_open=_load_choice(env, f"{scope_u}__CIRCUIT_OPEN", _CIRCUIT_OPEN, "fail_fast"),
|
||||
**_load_pgw(env),
|
||||
)
|
||||
|
||||
|
||||
@@ -261,9 +261,7 @@ class SourceAdmission:
|
||||
)
|
||||
nap = self._nap(hint, clock)
|
||||
if hint > 0:
|
||||
logger.info(
|
||||
"熔断开路等待 {:.1f}s 后重试(scope={}, 原因={})", nap, self._scope, reasons
|
||||
)
|
||||
logger.info("熔断开路等待 {:.1f}s 后重试(scope={}, 原因={})", nap, self._scope, reasons)
|
||||
await self._sleep(nap)
|
||||
|
||||
def _nap(self, hint: float, clock: StallClock) -> float:
|
||||
|
||||
@@ -291,7 +291,6 @@ class TestRetryAfter:
|
||||
await _open_gate(gate, "s1") # s1 开路;s2 健康
|
||||
assert await gate.retry_after_s(("s1", "s2")) == 0.0
|
||||
|
||||
|
||||
async def test_half_open_rejection_reports_no_certain_wait(self, gate_factory, clock):
|
||||
"""探针在途时被拒 → 0.0(issue #14): 探针随时可能出结果,不存在确定时刻。
|
||||
|
||||
|
||||
@@ -628,8 +628,12 @@ class TestCircuitOpenPolicy:
|
||||
clock = FakeClock()
|
||||
src = make_source()
|
||||
mw = _mw(
|
||||
[src], self._free_limiter(clock, src), [], clock=clock,
|
||||
sleep=BoundedSleep(), gate=await self._opened_gate(clock),
|
||||
[src],
|
||||
self._free_limiter(clock, src),
|
||||
[],
|
||||
clock=clock,
|
||||
sleep=BoundedSleep(),
|
||||
gate=await self._opened_gate(clock),
|
||||
)
|
||||
with pytest.raises(CircuitOpenError) as ei:
|
||||
await mw(_REQ)
|
||||
@@ -650,8 +654,13 @@ class TestCircuitOpenPolicy:
|
||||
|
||||
sleep._side_effect = advance
|
||||
mw = _mw(
|
||||
[src], self._free_limiter(clock, src), [_ok()], clock=clock,
|
||||
sleep=sleep, gate=await self._opened_gate(clock), circuit_open="wait",
|
||||
[src],
|
||||
self._free_limiter(clock, src),
|
||||
[_ok()],
|
||||
clock=clock,
|
||||
sleep=sleep,
|
||||
gate=await self._opened_gate(clock),
|
||||
circuit_open="wait",
|
||||
)
|
||||
resp = await mw(_REQ)
|
||||
assert resp.content == "ok"
|
||||
@@ -671,8 +680,14 @@ class TestCircuitOpenPolicy:
|
||||
|
||||
sleep._side_effect = advance
|
||||
mw = _mw(
|
||||
[src], self._free_limiter(clock, src), [_ok()], clock=clock, sleep=sleep,
|
||||
gate=await self._opened_gate(clock), quota_full="fail_fast", circuit_open="wait",
|
||||
[src],
|
||||
self._free_limiter(clock, src),
|
||||
[_ok()],
|
||||
clock=clock,
|
||||
sleep=sleep,
|
||||
gate=await self._opened_gate(clock),
|
||||
quota_full="fail_fast",
|
||||
circuit_open="wait",
|
||||
)
|
||||
assert (await mw(_REQ)).content == "ok"
|
||||
|
||||
@@ -694,8 +709,13 @@ class TestCircuitOpenPolicy:
|
||||
|
||||
sleep._side_effect = advance
|
||||
mw = _mw(
|
||||
[src], self._free_limiter(clock, src), [], clock=clock, sleep=sleep,
|
||||
gate=await self._opened_gate(clock, long_cooldown), circuit_open="wait",
|
||||
[src],
|
||||
self._free_limiter(clock, src),
|
||||
[],
|
||||
clock=clock,
|
||||
sleep=sleep,
|
||||
gate=await self._opened_gate(clock, long_cooldown),
|
||||
circuit_open="wait",
|
||||
)
|
||||
with pytest.raises(AllSourcesExhausted) as ei:
|
||||
await mw(_REQ)
|
||||
@@ -708,8 +728,13 @@ class TestCircuitOpenPolicy:
|
||||
clock = FakeClock()
|
||||
src = make_source()
|
||||
mw = _mw(
|
||||
[src], self._free_limiter(clock, src), [], clock=clock,
|
||||
sleep=asyncio.sleep, gate=await self._opened_gate(clock), circuit_open="wait",
|
||||
[src],
|
||||
self._free_limiter(clock, src),
|
||||
[],
|
||||
clock=clock,
|
||||
sleep=asyncio.sleep,
|
||||
gate=await self._opened_gate(clock),
|
||||
circuit_open="wait",
|
||||
)
|
||||
task = asyncio.create_task(mw(_REQ))
|
||||
await asyncio.sleep(0.03)
|
||||
|
||||
@@ -177,9 +177,7 @@ class TestResilienceKeys:
|
||||
是"快速失败 → 长时间挂起"这个最危险的方向,不能强加给存量下游。
|
||||
"""
|
||||
assert GatewaySettings.from_env("LLM", env=_env()).circuit_open == "fail_fast"
|
||||
waiting = GatewaySettings.from_env(
|
||||
"LLM", env=_env(**{"LLM__CIRCUIT_OPEN": "wait"})
|
||||
)
|
||||
waiting = GatewaySettings.from_env("LLM", env=_env(**{"LLM__CIRCUIT_OPEN": "wait"}))
|
||||
assert waiting.circuit_open == "wait"
|
||||
with pytest.raises(ValueError, match="CIRCUIT_OPEN"):
|
||||
GatewaySettings.from_env("LLM", env=_env(**{"LLM__CIRCUIT_OPEN": "block"}))
|
||||
|
||||
Reference in New Issue
Block a user