Skip to content

Commit 80fc58c

Browse files
committed
fix tests
1 parent 6d414f5 commit 80fc58c

File tree

3 files changed

+10
-42
lines changed

3 files changed

+10
-42
lines changed

tests/test_asyncio/test_connection_pool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import re
3+
from itertools import chain
34

45
import pytest
56
import pytest_asyncio
@@ -35,7 +36,7 @@ async def create_two_conn(r: redis.Redis):
3536
def has_no_connected_connections(pool: redis.ConnectionPool):
3637
return not any(
3738
x.is_connected
38-
for x in pool._available_connections + list(pool._in_use_connections)
39+
for x in chain(pool._available_connections, pool._in_use_connections)
3940
)
4041

4142
async def test_auto_disconnect_redis_created_pool(self, r: redis.Redis):

tests/test_connection_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def test_on_connect_error(self):
502502
bad_connection.info()
503503
pool = bad_connection.connection_pool
504504
assert len(pool._available_connections) == 1
505-
assert not pool._available_connections[0]._sock
505+
assert not list(pool._available_connections)[0]._sock
506506

507507
@pytest.mark.onlynoncluster
508508
@skip_if_server_version_lt("2.8.8")

tests/test_sentinel_managed_connection.py

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,12 @@
1-
import socket
21
from typing import Tuple
32
from unittest import mock
43

54
import pytest
6-
from redis.asyncio.retry import Retry
7-
from redis.asyncio.sentinel import (
5+
from redis.sentinel import (
86
Sentinel,
97
SentinelConnectionPool,
108
SentinelManagedConnection,
119
)
12-
from redis.backoff import NoBackoff
13-
14-
pytestmark = pytest.mark.asyncio
15-
16-
17-
def test_connect_retry_on_timeout_error(connect_args):
18-
"""Test that the _connect function is retried in case of a timeout"""
19-
connection_pool = mock.AsyncMock()
20-
connection_pool.get_master_address = mock.AsyncMock(
21-
return_value=(connect_args["host"], connect_args["port"])
22-
)
23-
conn = SentinelManagedConnection(
24-
retry_on_timeout=True,
25-
retry=Retry(NoBackoff(), 3),
26-
connection_pool=connection_pool,
27-
)
28-
origin_connect = conn._connect
29-
conn._connect = mock.AsyncMock()
30-
31-
async def mock_connect():
32-
# connect only on the last retry
33-
if conn._connect.call_count <= 2:
34-
raise socket.timeout
35-
else:
36-
return await origin_connect()
37-
38-
conn._connect.side_effect = mock_connect
39-
conn.connect()
40-
assert conn._connect.call_count == 3
41-
conn.disconnect()
42-
4310

4411
class SentinelManagedConnectionMock(SentinelManagedConnection):
4512
def connect_to_same_address(self) -> None:
@@ -125,7 +92,7 @@ def test_connects_to_same_address_if_same_id_replica(
12592
"""
12693
Assert that the connection address is the same if the ``_iter_req_id`` is the same
12794
when we are in replica mode using a
128-
:py:class:`~redis.asyncio.sentinel.SentinelConnectionPool`.
95+
:py:class:`~redis.sentinel.SentinelConnectionPool`.
12996
"""
13097
connection_for_req_1 = connection_pool_replica_mock.get_connection(
13198
"ANY", _iter_req_id=1
@@ -142,7 +109,7 @@ def test_connects_to_same_conn_object_if_same_id_and_conn_released_replica(
142109
"""
143110
Assert that the connection object is the same if the ``_iter_req_id`` is the same
144111
when we are in replica mode using a
145-
:py:class:`~redis.asyncio.sentinel.SentinelConnectionPool`
112+
:py:class:`~redis.sentinel.SentinelConnectionPool`
146113
and if we release the connection back to the connection pool before
147114
trying to connect again.
148115
"""
@@ -185,7 +152,7 @@ def test_connects_to_same_address_if_same_iter_req_id_master(
185152
"""
186153
Assert that the connection address is the same if the ``_iter_req_id`` is the same
187154
when we are in master mode using a
188-
:py:class:`~redis.asyncio.sentinel.SentinelConnectionPool`.
155+
:py:class:`~redis.sentinel.SentinelConnectionPool`.
189156
"""
190157
connection_for_req_1 = connection_pool_master_mock.get_connection(
191158
"ANY", _iter_req_id=1
@@ -202,7 +169,7 @@ def test_connects_to_same_conn_object_if_same_iter_req_id_and_released_master(
202169
"""
203170
Assert that the connection address is the same if the ``_iter_req_id`` is the same
204171
when we are in master mode using a
205-
:py:class:`~redis.asyncio.sentinel.SentinelConnectionPool`
172+
:py:class:`~redis.sentinel.SentinelConnectionPool`
206173
and if we release the connection back to the connection pool before
207174
trying to connect again.
208175
"""
@@ -222,7 +189,7 @@ def test_connects_to_same_address_if_no_iter_req_id_master(
222189
Assert that connection address is always the same regardless if
223190
there's an ``iter_req_id`` or not
224191
when we are in master mode using a
225-
:py:class:`~redis.asyncio.sentinel.SentinelConnectionPool`.
192+
:py:class:`~redis.sentinel.SentinelConnectionPool`.
226193
"""
227194
connection_for_req_1 = connection_pool_master_mock.get_connection(
228195
"ANY", _iter_req_id=1
@@ -244,7 +211,7 @@ def test_scan_iter_family_cleans_up(
244211
connection_pool_replica_mock: SentinelConnectionPool,
245212
):
246213
"""Test that connection pool is correctly cleaned up"""
247-
from redis.asyncio import Redis
214+
from redis import Redis
248215

249216
r = Redis(connection_pool=connection_pool_replica_mock)
250217

0 commit comments

Comments
 (0)