-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Description
Severity
High
Location
File: tests/test_threads.py and general test coverage
Description
While there are basic concurrency tests (test_two_threads, test_pool_map), there are no stress tests for critical edge cases:
- Cache stampede scenarios: Multiple concurrent requests with same arguments hitting cache miss
- High contention on single keys: Many threads accessing same cache key simultaneously
- Redis connection failures: Cache behavior during network issues
- Concurrent eviction during writes: Race conditions during maxsize eviction
Impact
The documented race condition (README.md:1029-1030) is not tested or demonstrated, making it difficult to verify fixes.
Proposed Tests
async def test_cache_stampede_concurrent_misses():
\"\"\"Test that concurrent misses don't all execute the function.\"\"\"
cache = RedisFuncCache("stampede", LruTPolicy(), ...)
call_count = 0
@cache
async def expensive_func(x):
nonlocal call_count
call_count += 1
await asyncio.sleep(0.5) # Simulate slow operation
return x
# 10 concurrent calls with same arguments
results = await asyncio.gather(*[expensive_func(42) for _ in range(10)])
# With proper locking, call_count should be ~1-2, not 10
assert call_count < 5 # Allow some tolerance
async def test_high_contention_single_key():
\"\"\"Test many concurrent accesses to the same key.\"\"\"
# 100+ concurrent operations on single cache entry
async def test_redis_connection_failure():
\"\"\"Test cache behavior when Redis becomes unavailable.\"\"\"
# Should fail gracefully or use fallback
async def test_concurrent_eviction():
\"\"\"Test concurrent writes during maxsize eviction.\"\"\"
# Multiple threads triggering eviction simultaneouslyAdditional Context
- Use asyncio.gather() or ThreadPoolExecutor for concurrency
- Use slower functions to expose stampede vulnerability
- Consider using pytest-asyncio for async test support
- Tests should validate both correctness and performance
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers