Skip to content

Commit 59c4cf0

Browse files
committed
Use correct redis url if not default when creating Connection
1 parent 1f051d6 commit 59c4cf0

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

tests/test_asyncio/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,13 @@ async def __aexit__(self, exc_type, exc_inst, tb):
253253

254254
def asynccontextmanager(func):
255255
return _asynccontextmanager(func)
256+
257+
# helpers to get the connection arguments for this run
258+
@pytest.fixture()
259+
def redis_url(request):
260+
return request.config.getoption("--redis-url")
261+
262+
@pytest.fixture()
263+
def connect_args(request):
264+
url = request.config.getoption("--redis-url")
265+
return parse_url(url)

tests/test_asyncio/test_connection.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ async def test_can_run_concurrent_commands(r):
125125
assert all(await asyncio.gather(*(r.ping() for _ in range(10))))
126126

127127

128-
async def test_connect_retry_on_timeout_error():
128+
async def test_connect_retry_on_timeout_error(connect_args):
129129
"""Test that the _connect function is retried in case of a timeout"""
130-
conn = Connection(retry_on_timeout=True, retry=Retry(NoBackoff(), 3))
130+
conn = Connection(
131+
retry_on_timeout=True, retry=Retry(NoBackoff(), 3), **connect_args
132+
)
131133
origin_connect = conn._connect
132134
conn._connect = mock.AsyncMock()
133135

@@ -200,7 +202,7 @@ async def test_connection_parse_response_resume(r: redis.Redis):
200202
[_AsyncRESP2Parser, _AsyncRESP3Parser, _AsyncHiredisParser],
201203
ids=["AsyncRESP2Parser", "AsyncRESP3Parser", "AsyncHiredisParser"],
202204
)
203-
async def test_connection_disconect_race(parser_class):
205+
async def test_connection_disconect_race(parser_class, connect_args):
204206
"""
205207
This test reproduces the case in issue #2349
206208
where a connection is closed while the parser is reading to feed the
@@ -215,10 +217,9 @@ async def test_connection_disconect_race(parser_class):
215217
if parser_class == _AsyncHiredisParser and not HIREDIS_AVAILABLE:
216218
pytest.skip("Hiredis not available")
217219

218-
args = {}
219-
args["parser_class"] = parser_class
220+
connect_args["parser_class"] = parser_class
220221

221-
conn = Connection(**args)
222+
conn = Connection(**connect_args)
222223

223224
cond = asyncio.Condition()
224225
# 0 == initial

tests/test_asyncio/test_sentinel_managed_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
pytestmark = pytest.mark.asyncio
1111

1212

13-
async def test_connect_retry_on_timeout_error():
13+
async def test_connect_retry_on_timeout_error(connect_args):
1414
"""Test that the _connect function is retried in case of a timeout"""
1515
connection_pool = mock.AsyncMock()
1616
connection_pool.get_master_address = mock.AsyncMock(
17-
return_value=("localhost", 6379)
17+
return_value=(connect_args["host"], connect_args["port"])
1818
)
1919
conn = SentinelManagedConnection(
2020
retry_on_timeout=True,

0 commit comments

Comments
 (0)