fix tests
This commit is contained in:
@@ -382,6 +382,58 @@ class DownloadService:
|
||||
f"Failed to reorder: {str(e)}"
|
||||
) from e
|
||||
|
||||
async def reorder_queue_bulk(self, item_order: List[str]) -> bool:
|
||||
"""Reorder pending queue to match provided item order for the specified
|
||||
item IDs. Any pending items not mentioned will be appended after the
|
||||
ordered items preserving their relative order.
|
||||
|
||||
Args:
|
||||
item_order: Desired ordering of item IDs for pending queue
|
||||
|
||||
Returns:
|
||||
True if operation completed
|
||||
"""
|
||||
try:
|
||||
# Map existing pending items by id
|
||||
existing = {item.id: item for item in list(self._pending_queue)}
|
||||
|
||||
new_queue: List[DownloadItem] = []
|
||||
|
||||
# Add items in the requested order if present
|
||||
for item_id in item_order:
|
||||
item = existing.pop(item_id, None)
|
||||
if item:
|
||||
new_queue.append(item)
|
||||
|
||||
# Append any remaining items preserving original order
|
||||
for item in list(self._pending_queue):
|
||||
if item.id in existing:
|
||||
new_queue.append(item)
|
||||
existing.pop(item.id, None)
|
||||
|
||||
# Replace pending queue
|
||||
self._pending_queue = deque(new_queue)
|
||||
|
||||
self._save_queue()
|
||||
|
||||
# Broadcast queue status update
|
||||
queue_status = await self.get_queue_status()
|
||||
await self._broadcast_update(
|
||||
"queue_status",
|
||||
{
|
||||
"action": "queue_bulk_reordered",
|
||||
"item_order": item_order,
|
||||
"queue_status": queue_status.model_dump(mode="json"),
|
||||
},
|
||||
)
|
||||
|
||||
logger.info("Bulk queue reorder applied", ordered_count=len(item_order))
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Failed to apply bulk reorder", error=str(e))
|
||||
raise DownloadServiceError(f"Failed to reorder: {str(e)}") from e
|
||||
|
||||
async def get_queue_status(self) -> QueueStatus:
|
||||
"""Get current status of all queues.
|
||||
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user