fix: address M2 verifier findings in soak harness

This commit is contained in:
2026-07-21 02:05:49 -04:00
parent 724dc3c328
commit 326dd24dd1
10 changed files with 214 additions and 20 deletions
+47
View File
@@ -195,3 +195,50 @@ class TestInvariants:
_row("c", session="r-p1"), # 非 P3 剔除
]
assert structured_success_rate(rows, session_suffix="-p3") == pytest.approx(0.5)
class TestLiveInvariantsAndCaps:
def test_capped_budget_clamps_to_signed_values(self):
from tools.soak.scoreboard import capped_budget
assert capped_budget("P1", 9999) == 500
assert capped_budget("P6", 100) == 100
async def test_gate_reenterable_detects_hung_probe(self):
from tools.soak.scoreboard import inv_gate_reenterable
class _Decision:
def __init__(self, allowed, state, is_probe=False):
self.allowed = allowed
self.state = state
self.is_probe = is_probe
self.retry_after_s = 30.0
class _Gate:
def __init__(self, decision):
self._d = decision
self.released = 0
async def try_enter(self, name, owner):
return self._d
async def release_probe(self, entry):
self.released += 1
healthy = _Gate(_Decision(True, "closed"))
await inv_gate_reenterable(healthy, ["s1"])
probe_gate = _Gate(_Decision(True, "half_open", is_probe=True))
await inv_gate_reenterable(probe_gate, ["s1"])
assert probe_gate.released == 1 # 探针当场归还,不留新悬挂
await inv_gate_reenterable(_Gate(_Decision(False, "open")), ["s1"]) # 冷却合法
with pytest.raises(AssertionError, match="悬挂"):
await inv_gate_reenterable(_Gate(_Decision(False, "half_open")), ["s1"])
def test_fault_errors_presence(self):
from tools.soak.scoreboard import inv_fault_errors_present
rows = [_row("a", source="bad_1", error="SourceDeadError: 401"), _row("b")]
inv_fault_errors_present(rows, fault_source_names=["bad_1"])
inv_fault_errors_present(rows, fault_source_names=[]) # 未配故障源直接通过
with pytest.raises(AssertionError):
inv_fault_errors_present([_row("c")], fault_source_names=["bad_1"])