Skip to content

Commit 0f7666c

Browse files
committed
Fixing flaky test + exclude cache enabled test for servers <7.4
1 parent 3768c42 commit 0f7666c

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

tests/maint_notifications/test_cluster_maint_notifications_handling.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ def test_oss_maint_handler_propagation(self):
411411
conn, cluster, cluster.maint_notifications_config
412412
)
413413

414+
@skip_if_server_version_lt("7.4.0")
414415
def test_oss_maint_handler_propagation_cache_enabled(self):
415416
"""Test that OSSMaintNotificationsHandler is propagated to all connections."""
416417
cluster = self._create_cluster_client(enable_cache=True)

tests/test_auth/test_token_manager.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
22
from datetime import datetime, timezone
33
from time import sleep
4-
from unittest.mock import AsyncMock, Mock
4+
from unittest.mock import Mock
55

66
import pytest
77
from redis.auth.err import RequestTokenErr, TokenRenewalErr
@@ -29,48 +29,38 @@ class TestTokenManager:
2929
)
3030
def test_success_token_renewal(self, exp_refresh_ratio):
3131
tokens = []
32+
errors = []
33+
34+
# Use a function to generate fresh tokens at request time
35+
# to avoid timing issues on slow CI runners
36+
def generate_token():
37+
now = datetime.now(timezone.utc).timestamp() * 1000
38+
return SimpleToken("value", now + 10000, now, {"oid": "test"})
39+
3240
mock_provider = Mock(spec=IdentityProviderInterface)
33-
mock_provider.request_token.side_effect = [
34-
SimpleToken(
35-
"value",
36-
(datetime.now(timezone.utc).timestamp() * 1000) + 100,
37-
(datetime.now(timezone.utc).timestamp() * 1000),
38-
{"oid": "test"},
39-
),
40-
SimpleToken(
41-
"value",
42-
(datetime.now(timezone.utc).timestamp() * 1000) + 150,
43-
(datetime.now(timezone.utc).timestamp() * 1000) + 50,
44-
{"oid": "test"},
45-
),
46-
SimpleToken(
47-
"value",
48-
(datetime.now(timezone.utc).timestamp() * 1000) + 170,
49-
(datetime.now(timezone.utc).timestamp() * 1000) + 70,
50-
{"oid": "test"},
51-
),
52-
SimpleToken(
53-
"value",
54-
(datetime.now(timezone.utc).timestamp() * 1000) + 190,
55-
(datetime.now(timezone.utc).timestamp() * 1000) + 90,
56-
{"oid": "test"},
57-
),
58-
]
41+
mock_provider.request_token.side_effect = (
42+
lambda *args, **kwargs: generate_token()
43+
)
5944

6045
def on_next(token):
6146
nonlocal tokens
6247
tokens.append(token)
6348

49+
def on_error(err):
50+
nonlocal errors
51+
errors.append(err)
52+
6453
mock_listener = Mock(spec=CredentialsListener)
6554
mock_listener.on_next = on_next
66-
mock_listener.on_error = AsyncMock() # Add this line
55+
mock_listener.on_error = on_error
6756

6857
retry_policy = RetryPolicy(1, 10)
6958
config = TokenManagerConfig(exp_refresh_ratio, 0, 1000, retry_policy)
7059
mgr = TokenManager(mock_provider, config)
7160
mgr.start(mock_listener)
7261
sleep(0.1)
7362

63+
assert len(errors) == 0, f"Unexpected errors: {errors}"
7464
assert len(tokens) > 0
7565

7666
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)