@@ -207,7 +207,22 @@ def test_connects_to_same_address_if_no_iter_req_id_master(
207
207
)
208
208
209
209
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 (
211
226
connection_pool_replica_mock : SentinelConnectionPool ,
212
227
):
213
228
"""Test that connection pool is correctly cleaned up"""
@@ -216,7 +231,14 @@ def test_scan_iter_family_cleans_up(
216
231
from redis .commands .core import ScanCommands
217
232
218
233
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
219
238
with mock .patch .object (r , "_send_command_parse_response" , return_value = (0 , [])):
239
+ r .execute ()
220
240
[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
221
243
assert not connection_pool_replica_mock ._iter_req_id_to_replica_address
222
244
0 commit comments