P1c: hasattr-Schutz in connect() — getattr-Pattern statt direktem Attributzugriff

connect() Z.1936: self._gate_sweep_task durch getattr(self, '_gate_sweep_task', None)
ersetzt. Beim ersten connect()-Aufruf nach Adapter-Instanziierung existiert
_gate_sweep_task noch nicht als Attribut — direkter Zugriff warf AttributeError
und connect() brach ab. disconnect() Z.6519 hatte den hasattr-Check bereits.

Konsistenz mit disconnect(): gleiches getattr-Pattern (Option 1 nach Rainer).

Test: test_connect_fresh_adapter_no_attribute_error
- Marker: @pytest.mark.outbound_gate
- Verifiziert: connect() auf frischem Adapter (ohne _gate_sweep_task) wirft
  kein AttributeError und erzeugt _gate_sweep_task korrekt.
- Coverage-Lücke geschlossen (Rainer-Review).
This commit is contained in:
Bernd (Hermes)
2026-07-30 09:10:07 +02:00
parent 54edbb57f7
commit 5c22391287
2 changed files with 79 additions and 2 deletions
+3 -2
View File
@@ -1933,8 +1933,9 @@ class RocketChatAdapter(BasePlatformAdapter):
self._listen_task = asyncio.create_task(self._listen_loop())
# P5 V9.x W2: OutboundGate Sweep-Loop (asyncio.create_task, nicht threading.Timer)
# ── P1c: Sweep-Task-Check vor Re-create ──
if self._gate_sweep_task is not None and not self._gate_sweep_task.done():
self._gate_sweep_task.cancel()
task = getattr(self, '_gate_sweep_task', None)
if task is not None and not task.done():
task.cancel()
self._gate_sweep_task = asyncio.create_task(self._gate_sweep_loop())
self._last_activity = time.time()
logger.info("[rocketchat] Listen loop started, _running=%s", self._running)