fix(presence): Pulse-Engine Timeout-Hardening (Rainer Architects Review)
6 hardcoded Werte in PulseController geaendert: - _await_timeout: 1.0 → 4.0s (DDP setDefaultStatus braucht mehr Zeit) - _away_pulse_interval: 3.0 → 6.0s (seltener, vermeidet 429) - _busy_pulse_interval: 1.5 → 4.0s (nicht zu aggressiv) - _breaker_429_threshold: 1 → 3 (nicht sofort nach erstem 429 oeffnen) - _backoff_intervals: (5,15,60) → (10,30,60) (sanftere Eskalation) - _breaker_cooldown_s: 30.0 → 45.0s (laengere Erholungsphase) Tests: threshold-abhaengige Tests dynamisch auf _breaker_429_threshold umgestellt. 103/106 passed (3 pre-existing pgrep-mock Fehler). ENV-Check: ROCKETCHAT_PRESENCE_PULSE_INTERVAL setzt nur initialen _pulse_interval, set_pulse_target ueberschreibt mit mode-spezifischen Werten — neue Defaults greifen korrekt.
This commit is contained in:
@@ -2347,7 +2347,7 @@ class TestCircuitBreakerStateTransitions:
|
||||
assert pc.get_consecutive_429s() == 0
|
||||
|
||||
def test_one_429_opens_breaker(self):
|
||||
"""V8.8: 1×429 → CLOSED→OPEN sofort (threshold=1)."""
|
||||
"""V8.9: threshold×429 → CLOSED→OPEN (threshold=3)."""
|
||||
from plugin.archivar.presence_engine import PulseController
|
||||
|
||||
mock_ddp = MagicMock()
|
||||
@@ -2360,11 +2360,12 @@ class TestCircuitBreakerStateTransitions:
|
||||
|
||||
base_interval = pc.get_effective_pulse_interval()
|
||||
|
||||
# Tick 1: 429 #1 → OPEN (threshold=1)
|
||||
pc._pulse_tick()
|
||||
# threshold×429 → OPEN
|
||||
for _ in range(pc._breaker_429_threshold):
|
||||
pc._pulse_tick()
|
||||
assert pc.get_breaker_state() == "OPEN"
|
||||
assert pc.get_consecutive_429s() == 1
|
||||
# pulse_interval sollte auf backoff_level=0 → 5.0s gestiegen sein
|
||||
assert pc.get_consecutive_429s() == pc._breaker_429_threshold
|
||||
# pulse_interval sollte auf backoff_level=0 → 10.0s gestiegen sein
|
||||
assert pc.get_effective_pulse_interval() > base_interval
|
||||
|
||||
def test_breaker_blocks_ticks_when_open(self):
|
||||
@@ -2378,8 +2379,9 @@ class TestCircuitBreakerStateTransitions:
|
||||
pc = PulseController(pulse_interval=0.05, _clamp_pulse=False)
|
||||
pc.bind_ddp(mock_ddp)
|
||||
|
||||
# 1×429 → OPEN (threshold=1)
|
||||
pc._pulse_tick()
|
||||
# threshold×429 → OPEN
|
||||
for _ in range(pc._breaker_429_threshold):
|
||||
pc._pulse_tick()
|
||||
assert pc.get_breaker_state() == "OPEN"
|
||||
|
||||
# Weitere Ticks werden geblockt (kein DDP-Call mehr)
|
||||
@@ -2397,12 +2399,12 @@ class TestCircuitBreakerHalfOpen:
|
||||
"""HALF_OPEN Test-Ping success → CLOSED, pulse_interval reset."""
|
||||
from plugin.archivar.presence_engine import PulseController
|
||||
|
||||
# DDP wirft 1×429, dann success (threshold=1)
|
||||
# DDP wirft threshold×429, dann success
|
||||
call_count = [0]
|
||||
|
||||
def ddp_side_effect(status):
|
||||
call_count[0] += 1
|
||||
if call_count[0] <= 1:
|
||||
if call_count[0] <= pc._breaker_429_threshold:
|
||||
raise Exception("HTTP 429 Too Many Requests")
|
||||
return True
|
||||
|
||||
@@ -2413,8 +2415,9 @@ class TestCircuitBreakerHalfOpen:
|
||||
pc = PulseController(pulse_interval=0.05, _clamp_pulse=False)
|
||||
pc.bind_ddp(mock_ddp)
|
||||
|
||||
# 1×429 → OPEN (threshold=1)
|
||||
pc._pulse_tick()
|
||||
# threshold×429 → OPEN
|
||||
for _ in range(pc._breaker_429_threshold):
|
||||
pc._pulse_tick()
|
||||
assert pc.get_breaker_state() == "OPEN"
|
||||
|
||||
# Simuliere Cooldown-Ablauf: setze _breaker_opened_at in die Vergangenheit
|
||||
@@ -2439,15 +2442,16 @@ class TestCircuitBreakerHalfOpen:
|
||||
pc = PulseController(pulse_interval=0.05, _clamp_pulse=False)
|
||||
pc.bind_ddp(mock_ddp)
|
||||
|
||||
# 1×429 → OPEN (threshold=1, backoff_level=0, pulse_interval=5.0)
|
||||
pc._pulse_tick()
|
||||
# threshold×429 → OPEN (backoff_level=0, pulse_interval=10.0)
|
||||
for _ in range(pc._breaker_429_threshold):
|
||||
pc._pulse_tick()
|
||||
assert pc.get_breaker_state() == "OPEN"
|
||||
first_open_interval = pc.get_effective_pulse_interval()
|
||||
|
||||
# Simuliere Cooldown-Ablauf
|
||||
pc._breaker_opened_at = time.monotonic() - pc._breaker_cooldown_s - 1.0
|
||||
|
||||
# HALF_OPEN Test-Ping → 429 → OPEN again, backoff_level=1 → 15.0s
|
||||
# HALF_OPEN Test-Ping → 429 → OPEN again, backoff_level=1 → 30.0s
|
||||
pc._pulse_tick()
|
||||
assert pc.get_breaker_state() == "OPEN"
|
||||
assert pc.get_effective_pulse_interval() > first_open_interval
|
||||
@@ -2457,7 +2461,7 @@ class TestCircuitBreakerSustained429:
|
||||
"""P1: sustained-429 — adaptives pulse_interval steigt unter Last."""
|
||||
|
||||
def test_sustained_429_escalates_pulse_interval(self):
|
||||
"""Anhaltende 429 → pulse_interval: 1.5s → 5s → 15s → 60s."""
|
||||
"""Anhaltende 429 → pulse_interval: 1.5s → 10s → 30s → 60s."""
|
||||
from plugin.archivar.presence_engine import PulseController
|
||||
|
||||
mock_ddp = MagicMock()
|
||||
@@ -2469,11 +2473,12 @@ class TestCircuitBreakerSustained429:
|
||||
|
||||
intervals_seen = [pc.get_effective_pulse_interval()]
|
||||
|
||||
# Zyklus 1: 1×429 → OPEN (threshold=1, backoff 0: 5.0s)
|
||||
pc._pulse_tick()
|
||||
# Zyklus 1: threshold×429 → OPEN (backoff 0: 10.0s)
|
||||
for _ in range(pc._breaker_429_threshold):
|
||||
pc._pulse_tick()
|
||||
intervals_seen.append(pc.get_effective_pulse_interval())
|
||||
|
||||
# Cooldown ablaufen lassen → HALF_OPEN → 429 → OPEN (backoff 1: 15.0s)
|
||||
# Cooldown ablaufen lassen → HALF_OPEN → 429 → OPEN (backoff 1: 30.0s)
|
||||
pc._breaker_opened_at = time.monotonic() - pc._breaker_cooldown_s - 1.0
|
||||
pc._pulse_tick()
|
||||
intervals_seen.append(pc.get_effective_pulse_interval())
|
||||
@@ -2507,8 +2512,9 @@ class TestCircuitBreakerSustained429:
|
||||
|
||||
# 5 Zyklen OPEN→HALF_OPEN→OPEN (mehr als backoff_intervals Länge)
|
||||
for cycle in range(5):
|
||||
# 1×429 → OPEN (threshold=1)
|
||||
pc._pulse_tick()
|
||||
# threshold×429 → OPEN
|
||||
for _ in range(pc._breaker_429_threshold):
|
||||
pc._pulse_tick()
|
||||
# Cooldown ablaufen → HALF_OPEN → 429 → OPEN
|
||||
pc._breaker_opened_at = time.monotonic() - pc._breaker_cooldown_s - 1.0
|
||||
pc._pulse_tick()
|
||||
@@ -2589,8 +2595,9 @@ class TestCircuitBreakerDdpErrorClassification:
|
||||
pc.bind_ddp(mock_ddp)
|
||||
pc.bind_rest(mock_rest)
|
||||
|
||||
# 1×429 DDP → OPEN (threshold=1), REST wurde NIE aufgerufen
|
||||
pc._pulse_tick()
|
||||
# threshold×429 DDP → OPEN, REST wurde NIE aufgerufen
|
||||
for _ in range(pc._breaker_429_threshold):
|
||||
pc._pulse_tick()
|
||||
|
||||
# REST wurde NICHT aufgerufen (429 blockiert Fallback)
|
||||
mock_rest._request.assert_not_called()
|
||||
@@ -2626,7 +2633,7 @@ class TestCircuitBreakerRecordSuccess:
|
||||
|
||||
def ddp_side_effect(status):
|
||||
call_count[0] += 1
|
||||
if call_count[0] <= 1:
|
||||
if call_count[0] <= pc._breaker_429_threshold:
|
||||
raise Exception("HTTP 429 Too Many Requests")
|
||||
return True
|
||||
|
||||
@@ -2637,10 +2644,11 @@ class TestCircuitBreakerRecordSuccess:
|
||||
pc = PulseController(pulse_interval=1.5, _clamp_pulse=False)
|
||||
pc.bind_ddp(mock_ddp)
|
||||
|
||||
# 1×429 → OPEN (threshold=1, pulse_interval=5.0)
|
||||
pc._pulse_tick()
|
||||
# threshold×429 → OPEN (backoff_level=0, pulse_interval=10.0)
|
||||
for _ in range(pc._breaker_429_threshold):
|
||||
pc._pulse_tick()
|
||||
assert pc.get_breaker_state() == "OPEN"
|
||||
assert pc.get_effective_pulse_interval() == 5.0
|
||||
assert pc.get_effective_pulse_interval() == 10.0
|
||||
|
||||
# Cooldown ablaufen → HALF_OPEN → success → CLOSED
|
||||
pc._breaker_opened_at = time.monotonic() - pc._breaker_cooldown_s - 1.0
|
||||
|
||||
Reference in New Issue
Block a user