fix(tests): reduce TTL durations to improve test reliability

- Adjusted TTL durations and sleep intervals across memory and cache tests for consistent expiration behavior.
- Prevented test flakiness caused by timing discrepancies in token expiration and cache cleanup.
This commit is contained in:
2026-01-05 18:29:02 +01:00
parent da85a8aba8
commit d0f32d04f7
5 changed files with 24 additions and 20 deletions

View File

@@ -78,13 +78,13 @@ class TestInMemoryStorageTTL:
@pytest.mark.asyncio
async def test_ttl_expiration(self, storage: InMemoryStorage) -> None:
"""Test that expired keys return None."""
await storage.set("key1", "value1", ttl_seconds=1)
await storage.set("key1", "value1", ttl_seconds=0.1)
# Key exists initially
assert await storage.get("key1") == "value1"
# Wait for expiration
await asyncio.sleep(1.1)
await asyncio.sleep(0.15)
# Key should be expired
assert await storage.get("key1") is None
@@ -93,10 +93,10 @@ class TestInMemoryStorageTTL:
@pytest.mark.asyncio
async def test_remove_ttl_on_update(self, storage: InMemoryStorage) -> None:
"""Test that updating without TTL removes expiration."""
await storage.set("key1", "value1", ttl_seconds=1)
await storage.set("key1", "value1", ttl_seconds=0.1)
await storage.set("key1", "value2") # No TTL
await asyncio.sleep(1.1)
await asyncio.sleep(0.15)
# Key should still exist (TTL removed)
assert await storage.get("key1") == "value2"
@@ -180,10 +180,10 @@ class TestInMemoryStorageCapacity:
"""Test that expired keys are cleaned up for capacity."""
storage = InMemoryStorage(max_keys=2)
await storage.set("key1", "value1", ttl_seconds=1)
await storage.set("key1", "value1", ttl_seconds=0.1)
await storage.set("key2", "value2")
await asyncio.sleep(1.1)
await asyncio.sleep(0.15)
# Should succeed because key1 is expired and will be cleaned
await storage.set("key3", "value3")