Skip to content

Commit 2544bdd

Browse files
committed
fix some tests
1 parent 360f3a8 commit 2544bdd

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

redis/asyncio/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,9 @@ async def execute_command(self, *args, **options):
651651
finally:
652652
if not self.connection:
653653
await pool.release(conn)
654-
if "ITER" in command_name.upper():
654+
# Do additional cleanup if this is part of a SCAN ITER family command.
655+
# It's possible that this is just a pure SCAN family command though.
656+
if "SCAN" in command_name.upper():
655657
pool.cleanup(iter_req_id=options.get("iter_req_id", None))
656658

657659
async def parse_response(

redis/asyncio/sentinel.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ async def get_connection(
253253
should go to the same replica.
254254
"""
255255
# If not an iter command or in master mode, call superclass' implementation
256+
breakpoint()
256257
if not (iter_req_id := options.get("iter_req_id", None)) or self.is_master:
257258
return await super().get_connection(command_name, *keys, **options)
258259

@@ -292,7 +293,9 @@ async def get_connection(
292293
# This will connect to the host and port of the replica
293294
else:
294295
await connection.connect_to_address((server_host, server_port))
296+
breakpoint()
295297
await self.ensure_connection_connected_to_address(connection)
298+
breakpoint()
296299
except BaseException:
297300
# Release the connection back to the pool so that we don't
298301
# leak it

redis/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,10 @@ def execute_command(self, *args, **options):
581581
finally:
582582
if not self.connection:
583583
pool.release(conn)
584+
# Do additional cleanup if this is part of a SCAN ITER family command.
585+
# It's possible that this is just a pure SCAN family command though.
584586
if "SCAN" in command_name.upper():
585-
pool.cleanup(iter_req_id=options.get("_iter_req_id", None))
587+
pool.cleanup(iter_req_id=options.get("iter_req_id", None))
586588

587589
def parse_response(self, connection, command_name, **options):
588590
"""Parses a response from the Redis server"""

redis/sentinel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def _connect_retry(self, same_address: bool = False):
5454
if self.connection_pool.is_master:
5555
self.connect_to(self.connection_pool.get_master_address())
5656
else:
57+
breakpoint()
5758
for slave in self.connection_pool.rotate_slaves():
5859
try:
5960
return self.connect_to(slave)

tests/test_asyncio/test_sentinel_managed_connection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,6 @@ async def test_scan_iter_family_cleans_up(
251251

252252
r = Redis(connection_pool=connection_pool_replica_mock)
253253

254-
[k async for k in r.scan_iter("a")]
255-
assert not connection_pool_replica_mock.iter_req_id_to_replica_address
254+
with mock.patch.object(r, "_send_command_parse_response", return_value=(0, [])):
255+
[k async for k in r.scan_iter("a")]
256+
assert not connection_pool_replica_mock._iter_req_id_to_replica_address

0 commit comments

Comments
 (0)