chore: apply pending code updates
This commit is contained in:
@@ -4,6 +4,7 @@ This module tests the performance characteristics of batch NFO creation
|
||||
including concurrent operations, TMDB API request optimization, and memory usage.
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
@@ -15,6 +16,8 @@ from src.core.services.nfo_service import NFOService
|
||||
from src.server.api.nfo import batch_create_nfo
|
||||
from src.server.models.nfo import NFOBatchCreateRequest
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestConcurrentNFOCreation:
|
||||
"""Test performance of concurrent NFO creation operations."""
|
||||
@@ -83,8 +86,11 @@ class TestConcurrentNFOCreation:
|
||||
# Concurrent should take roughly (num_series / 5) * 0.1 = 0.2s
|
||||
assert elapsed_time < 1.0, "Concurrency not providing speedup"
|
||||
|
||||
print(f"\nPerformance: {num_series} series in {elapsed_time:.2f}s")
|
||||
print(f"Rate: {num_series / elapsed_time:.2f} series/second")
|
||||
logger.info("Batch NFO creation completed", extra={"num_series": num_series, "elapsed_s": elapsed_time})
|
||||
logger.debug(
|
||||
"Batch NFO creation rate",
|
||||
extra={"series_per_second": num_series / elapsed_time},
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_concurrent_nfo_creation_50_series(self):
|
||||
|
||||
@@ -4,6 +4,7 @@ This module tests the performance characteristics of WebSocket connections
|
||||
including concurrent clients, message throughput, and progress update throttling.
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
import time
|
||||
from typing import List
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
@@ -12,6 +13,8 @@ import pytest
|
||||
|
||||
from src.server.services.websocket_service import WebSocketService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MockWebSocket:
|
||||
"""Mock WebSocket client for testing."""
|
||||
@@ -82,8 +85,14 @@ class TestWebSocketConcurrentClients:
|
||||
for i in range(num_clients):
|
||||
await websocket_service.disconnect(f"client_{i:03d}")
|
||||
|
||||
print(f"\n100 clients: Broadcast in {elapsed_time:.2f}s")
|
||||
print(f"Average per client: {elapsed_time / num_clients * 1000:.2f}ms")
|
||||
logger.info("Broadcast completed for %d clients", num_clients, extra={"elapsed_s": elapsed_time})
|
||||
logger.debug(
|
||||
"Broadcast performance per client",
|
||||
extra={
|
||||
"num_clients": num_clients,
|
||||
"avg_ms_per_client": elapsed_time / num_clients * 1000,
|
||||
},
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_200_concurrent_clients_scalability(self):
|
||||
@@ -114,7 +123,7 @@ class TestWebSocketConcurrentClients:
|
||||
for i in range(num_clients):
|
||||
await websocket_service.disconnect(f"client_{i:03d}")
|
||||
|
||||
print(f"\n200 clients: Broadcast in {elapsed_time:.2f}s")
|
||||
logger.info("Broadcast completed for %d clients", num_clients, extra={"elapsed_s": elapsed_time})
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_connection_pool_efficiency(self):
|
||||
@@ -144,8 +153,8 @@ class TestWebSocketConcurrentClients:
|
||||
for i in range(num_clients):
|
||||
await websocket_service.disconnect(f"client_{i:02d}")
|
||||
|
||||
print(f"\nConnected {num_clients} clients in {connection_time:.3f}s")
|
||||
print(f"Average: {connection_time / num_clients * 1000:.2f}ms per connection")
|
||||
logger.info("Connected %d clients in %.3fs", num_clients, connection_time)
|
||||
logger.info("Average: %.2fms per connection", connection_time / num_clients * 1000)
|
||||
|
||||
|
||||
class TestMessageThroughput:
|
||||
@@ -192,8 +201,13 @@ class TestMessageThroughput:
|
||||
for i in range(num_clients):
|
||||
await websocket_service.disconnect(f"client_{i}")
|
||||
|
||||
print(f"\nThroughput: {messages_per_second:.2f} messages/second")
|
||||
print(f"Total: {num_messages} messages to {num_clients} clients in {elapsed_time:.2f}s")
|
||||
logger.info("Throughput: %.2f messages/second", messages_per_second)
|
||||
logger.info(
|
||||
"Total: %d messages to %d clients in %.2fs",
|
||||
num_messages,
|
||||
num_clients,
|
||||
elapsed_time,
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_high_frequency_updates(self):
|
||||
@@ -234,7 +248,7 @@ class TestMessageThroughput:
|
||||
for i in range(5):
|
||||
await websocket_service.disconnect(f"client_{i}")
|
||||
|
||||
print(f"\nHigh-frequency: {updates_per_second:.2f} updates/second")
|
||||
logger.info("High-frequency: %.2f updates/second", updates_per_second)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_burst_message_handling(self):
|
||||
@@ -275,7 +289,7 @@ class TestMessageThroughput:
|
||||
for i in range(num_clients):
|
||||
await websocket_service.disconnect(f"client_{i:02d}")
|
||||
|
||||
print(f"\nBurst: {num_messages} messages in {elapsed_time:.2f}s")
|
||||
logger.info("Burst: %d messages in %.2fs", num_messages, elapsed_time)
|
||||
|
||||
|
||||
class TestProgressUpdateThrottling:
|
||||
@@ -313,7 +327,10 @@ class TestProgressUpdateThrottling:
|
||||
|
||||
await websocket_service.disconnect("test_client")
|
||||
|
||||
print(f"\nThrottling: {len(client.received_messages)} updates sent (100 possible)")
|
||||
logger.info(
|
||||
"Throttling: %d updates sent (100 possible)",
|
||||
len(client.received_messages),
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_throttling_reduces_network_load(self):
|
||||
@@ -356,7 +373,11 @@ class TestProgressUpdateThrottling:
|
||||
for i in range(10):
|
||||
await websocket_service.disconnect(f"client_{i}")
|
||||
|
||||
print(f"\nThrottling: {throttled_updates}/1000 updates sent ({reduction_percent:.1f}% reduction)")
|
||||
logger.info(
|
||||
"Throttling: %d/1000 updates sent (%.1f%% reduction)",
|
||||
throttled_updates,
|
||||
reduction_percent,
|
||||
)
|
||||
|
||||
|
||||
class TestRoomIsolation:
|
||||
@@ -402,7 +423,7 @@ class TestRoomIsolation:
|
||||
for i in range(clients_per_room):
|
||||
await websocket_service.disconnect(f"{room}_client_{i:02d}")
|
||||
|
||||
print(f"\nRoom isolation: 3 rooms × 30 clients in {elapsed_time:.2f}s")
|
||||
logger.info("Room isolation: 3 rooms × 30 clients in %.2fs", elapsed_time)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_selective_room_broadcast_performance(self):
|
||||
@@ -435,7 +456,7 @@ class TestRoomIsolation:
|
||||
for i in range(clients_per_room):
|
||||
await websocket_service.disconnect(f"{room}_{i:02d}")
|
||||
|
||||
print(f"\nSelective broadcast: 25/100 clients in {elapsed_time:.3f}s")
|
||||
logger.info("Selective broadcast: 25/100 clients in %.3fs", elapsed_time)
|
||||
|
||||
|
||||
class TestConnectionStability:
|
||||
@@ -472,7 +493,7 @@ class TestConnectionStability:
|
||||
# All connections should be cleaned up
|
||||
assert len(websocket_service.manager._active_connections) == 0
|
||||
|
||||
print(f"\nRapid cycles: {cycles_per_second:.2f} cycles/second")
|
||||
logger.info("Rapid cycles: %.2f cycles/second", cycles_per_second)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_concurrent_connect_disconnect(self):
|
||||
@@ -497,7 +518,7 @@ class TestConnectionStability:
|
||||
# All should be cleaned up
|
||||
assert len(websocket_service.manager._active_connections) == 0
|
||||
|
||||
print(f"\nConcurrent ops: 30 clients in {elapsed_time:.2f}s")
|
||||
logger.info("Concurrent ops: 30 clients in %.2fs", elapsed_time)
|
||||
|
||||
|
||||
class TestMemoryEfficiency:
|
||||
@@ -533,8 +554,8 @@ class TestMemoryEfficiency:
|
||||
for i in range(100):
|
||||
await websocket_service.disconnect(f"mem_client_{i:03d}")
|
||||
|
||||
print(f"\nMemory: {memory_increase_mb:.2f}MB for 100 connections")
|
||||
print(f"Per connection: {per_connection_kb:.2f}KB")
|
||||
logger.info("Memory: %.2fMB for 100 connections", memory_increase_mb)
|
||||
logger.info("Per connection: %.2fKB", per_connection_kb)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_message_queue_memory_efficiency(self):
|
||||
@@ -567,5 +588,5 @@ class TestMemoryEfficiency:
|
||||
|
||||
await websocket_service.disconnect("queue_test")
|
||||
|
||||
print(f"\nMessage queue: {total_size} bytes for 100 messages")
|
||||
print(f"Average: {total_size / 100:.2f} bytes/message")
|
||||
logger.info("Message queue: %d bytes for 100 messages", total_size)
|
||||
logger.info("Average: %.2f bytes/message", total_size / 100)
|
||||
|
||||
Reference in New Issue
Block a user