This commit is contained in:
QuantumGhost
2025-11-13 07:19:12 +08:00
parent e47059514a
commit 43348ce1a6
15 changed files with 122 additions and 66 deletions

View File

@ -5,6 +5,14 @@ This module provides utility classes and functions for testing
Redis broadcast channel functionality.
"""
from .test_data import (
LARGE_MESSAGES,
SMALL_MESSAGES,
SPECIAL_MESSAGES,
BufferTestConfig,
ConcurrencyTestConfig,
ErrorTestConfig,
)
from .test_helpers import (
ConcurrentPublisher,
SubscriptionMonitor,
@ -12,25 +20,17 @@ from .test_helpers import (
measure_throughput,
wait_for_condition,
)
from .test_data import (
BufferTestConfig,
ConcurrencyTestConfig,
ErrorTestConfig,
LARGE_MESSAGES,
SMALL_MESSAGES,
SPECIAL_MESSAGES,
)
__all__ = [
"LARGE_MESSAGES",
"SMALL_MESSAGES",
"SPECIAL_MESSAGES",
"BufferTestConfig",
"ConcurrencyTestConfig",
"ConcurrentPublisher",
"ErrorTestConfig",
"SubscriptionMonitor",
"assert_message_order",
"measure_throughput",
"wait_for_condition",
"BufferTestConfig",
"ConcurrencyTestConfig",
"ErrorTestConfig",
"LARGE_MESSAGES",
"SMALL_MESSAGES",
"SPECIAL_MESSAGES",
]

View File

@ -75,7 +75,7 @@ VERY_LARGE_MESSAGES = [
SPECIAL_MESSAGES = [
b"", # Empty message
b"\x00\x01\x02", # Binary data with null bytes
"unicode_test_你好".encode("utf-8"), # Unicode
"unicode_test_你好".encode(), # Unicode
b"special_chars_!@#$%^&*()_+-=[]{}|;':\",./<>?", # Special characters
b"newlines\n\r\t", # Control characters
]
@ -241,8 +241,8 @@ EDGE_CASE_MESSAGES = [
b"\x00", # Single null byte
b"\xff", # Single max byte value
b"a", # Single ASCII character
"ä".encode("utf-8"), # Single unicode character (2 bytes)
"𐍈".encode("utf-8"), # Unicode character outside BMP (4 bytes)
"ä".encode(), # Single unicode character (2 bytes)
"𐍈".encode(), # Unicode character outside BMP (4 bytes)
b"\x00" * 1000, # 1000 null bytes
b"\xff" * 1000, # 1000 max byte values
]

View File

@ -8,7 +8,7 @@ operations, monitoring subscriptions, and measuring performance.
import logging
import threading
import time
from collections.abc import Callable, Generator
from collections.abc import Callable
from typing import Any
_logger = logging.getLogger(__name__)
@ -62,7 +62,7 @@ class ConcurrentPublisher:
if self.delay > 0:
time.sleep(self.delay)
except Exception as e:
_logger.error(f"Publisher {thread_id} error: {e}")
_logger.error("Publisher %s error: %s", thread_id, e)
with self._lock:
self.published_messages.append(messages)
@ -280,7 +280,7 @@ def assert_message_order(received: list[bytes], expected: list[bytes]) -> bool:
for i, (recv_msg, exp_msg) in enumerate(zip(received, expected)):
if recv_msg != exp_msg:
_logger.error(f"Message order mismatch at index {i}: expected {exp_msg}, got {recv_msg}")
_logger.error("Message order mismatch at index %s: expected %s, got %s", i, exp_msg, recv_msg)
return False
return True
@ -309,7 +309,7 @@ def measure_throughput(
operation()
count += 1
except Exception as e:
_logger.error(f"Operation failed: {e}")
_logger.error("Operation failed: %s", e)
break
elapsed = time.time() - start_time