Skip to content

Commit 2daefb8

Browse files
committed
add cleanup tests for pipeline
1 parent 1c88dc8 commit 2daefb8

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

redis/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ def execute_command(self, *args, **options):
582582
if not self.connection:
583583
pool.release(conn)
584584
if "SCAN" in command_name.upper():
585-
breakpoint()
586585
pool.cleanup(iter_req_id=options.get("_iter_req_id", None))
587586

588587
def parse_response(self, connection, command_name, **options):
@@ -764,6 +763,7 @@ def reset(self) -> None:
764763
self.patterns = {}
765764
self.pending_unsubscribe_patterns = set()
766765
self.subscribed_event.clear()
766+
self.connection_pool.cleanup(iter_req_id=options.get("_iter_req_id", None))
767767

768768
def close(self) -> None:
769769
self.reset()

tests/test_sentinel_managed_connection.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,22 @@ def test_connects_to_same_address_if_no_iter_req_id_master(
207207
)
208208

209209

210-
def test_scan_iter_family_cleans_up(
210+
def test_scan_iter_in_redis_cleans_up(
211+
connection_pool_replica_mock: SentinelConnectionPool,
212+
):
213+
"""Test that connection pool is correctly cleaned up"""
214+
from redis import Redis
215+
216+
r = Redis(connection_pool=connection_pool_replica_mock)
217+
# Patch the actual sending and parsing response from the Connection object
218+
# but still let the connection pool does all the necessary work
219+
with mock.patch.object(r, "_send_command_parse_response", return_value=(0, [])):
220+
[k for k in r.scan_iter("a")]
221+
# Test that the iter_req_id for the scan command is cleared at the
222+
# end of the SCAN ITER command
223+
assert not connection_pool_replica_mock._iter_req_id_to_replica_address
224+
225+
def test_scan_iter_in_pipeline_cleans_up(
211226
connection_pool_replica_mock: SentinelConnectionPool,
212227
):
213228
"""Test that connection pool is correctly cleaned up"""
@@ -216,7 +231,14 @@ def test_scan_iter_family_cleans_up(
216231
from redis.commands.core import ScanCommands
217232

218233
r = Redis(connection_pool=connection_pool_replica_mock)
234+
r.pipeline()
235+
r.scan_iter("a")
236+
# Patch the actual sending and parsing response from the Connection object
237+
# but still let the connection pool does all the necessary work
219238
with mock.patch.object(r, "_send_command_parse_response", return_value=(0, [])):
239+
r.execute()
220240
[k for k in r.scan_iter("a")]
241+
# Test that the iter_req_id for the scan command is cleared at the
242+
# end of the SCAN ITER command
221243
assert not connection_pool_replica_mock._iter_req_id_to_replica_address
222244

0 commit comments

Comments
 (0)