test: lock settlement on measured usage in RetryMW
This commit is contained in:
@@ -152,6 +152,25 @@ class TestSuccessPath:
|
||||
# 预扣 400,实际 15 → settle 后窗口只记 15
|
||||
assert (await limiter.source_stats("a")).tpm_used == 15
|
||||
|
||||
@pytest.mark.parametrize("usage_source", ["measured", "estimated"])
|
||||
async def test_settle_uses_measured_sum_when_usage_available(self, usage_source):
|
||||
"""用量可得(含打捞降级的 estimated)时结算恒取实测之和,不落派生兜底分支。"""
|
||||
src = _src("a", tpm=1000, est_tokens=400)
|
||||
result = TransportResult(
|
||||
content="ok",
|
||||
thinking="",
|
||||
prompt_tokens=40,
|
||||
completion_tokens=60,
|
||||
usage_source=usage_source,
|
||||
ttft_ms=12.0,
|
||||
max_inter_token_ms=3.0,
|
||||
raw={},
|
||||
)
|
||||
mw, limiter, *_ = _harness([src], [result])
|
||||
await mw(_REQ)
|
||||
# 预扣 400,实测 40+60 → settle 后窗口记 100(而非派生兜底的 400)
|
||||
assert (await limiter.source_stats("a")).tpm_used == 100
|
||||
|
||||
|
||||
class TestRetryAndFailover:
|
||||
async def test_transient_switches_source_then_succeeds(self):
|
||||
|
||||
Reference in New Issue
Block a user