fix tests

This commit is contained in:
2025-10-22 07:44:24 +02:00
parent 71841645cf
commit 3e50ec0149
5 changed files with 206 additions and 158 deletions

View File

@@ -62,8 +62,27 @@ class ConnectionManager:
metadata: Optional metadata to associate with the connection
"""
await websocket.accept()
async with self._lock:
# If a connection with the same ID already exists, remove it to
# prevent stale references during repeated test setups.
if connection_id in self._active_connections:
try:
await self._active_connections[connection_id].close()
except Exception:
# Ignore errors when closing test mocks
pass
# cleanup existing data
self._active_connections.pop(connection_id, None)
self._connection_metadata.pop(connection_id, None)
# Remove from any rooms to avoid stale membership
for room_members in list(self._rooms.values()):
room_members.discard(connection_id)
# Remove empty rooms
for room in list(self._rooms.keys()):
if not self._rooms[room]:
del self._rooms[room]
self._active_connections[connection_id] = websocket
self._connection_metadata[connection_id] = metadata or {}