Skip to content

Commit 241033d

Browse files
committed
add tests for all scan iter family
1 parent 19050fe commit 241033d

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

redis/commands/core.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -3081,7 +3081,7 @@ def sscan(
30813081
pieces.extend([b"MATCH", match])
30823082
if count is not None:
30833083
pieces.extend([b"COUNT", count])
3084-
return self.execute_command("SSCAN", *pieces,)
3084+
return self.execute_command("SSCAN", *pieces, **kwargs)
30853085

30863086
def sscan_iter(
30873087
self,
@@ -3306,11 +3306,7 @@ async def hscan_iter(
33063306
cursor = "0"
33073307
while cursor != 0:
33083308
cursor, data = await self.hscan(
3309-
<<<<<<< HEAD
3310-
name, cursor=cursor, match=match, count=count, no_values=no_values
3311-
=======
3312-
name, cursor=cursor, match=match, count=count, _iter_req_id=iter_req_id
3313-
>>>>>>> 39aaec6 (fix scan iter command issued to different replicas)
3309+
name, cursor=cursor, match=match, count=count, no_values=no_values, _iter_req_id=iter_req_id
33143310
)
33153311
if no_values:
33163312
for it in data:

tests/test_asyncio/test_sentinel_managed_connection.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import socket
22
from typing import Tuple
3-
from unittest.mock import AsyncMock
3+
from unittest.mock import AsyncMock, ANY
44

55
import pytest
66
import pytest_asyncio
7+
import uuid
78
from redis.asyncio.retry import Retry
9+
from redis.commands.core import AsyncScanCommands
810
from redis.asyncio.sentinel import (
911
Sentinel,
1012
SentinelConnectionPool,
@@ -244,3 +246,25 @@ async def test_connects_to_same_address_if_no_iter_req_id_master(
244246
await connection_pool_master_mock.get_connection("ANY_COMMAND"),
245247
connection_for_req_1,
246248
)
249+
250+
251+
async def test_scan_iter_family_executes_commands_with_same_iter_req_id():
252+
"""Assert that all calls to execute_command receives the _iter_req_id kwarg"""
253+
with mock.patch.object(
254+
AsyncScanCommands,
255+
"execute_command",
256+
AsyncMock(return_value=(0, []))
257+
) as mock_execute_command, mock.patch.object(uuid, "uuid4", return_value="uuid"):
258+
[a async for a in AsyncScanCommands().scan_iter()]
259+
mock_execute_command.assert_called_with('SCAN', '0', _iter_req_id="uuid")
260+
[a async for a in AsyncScanCommands().sscan_iter("")]
261+
mock_execute_command.assert_called_with('SSCAN', '', '0', _iter_req_id="uuid")
262+
with mock.patch.object(
263+
AsyncScanCommands,
264+
"execute_command",
265+
AsyncMock(return_value=(0, {}))
266+
) as mock_execute_command, mock.patch.object(uuid, "uuid4", return_value="uuid"):
267+
[a async for a in AsyncScanCommands().hscan_iter("")]
268+
mock_execute_command.assert_called_with('HSCAN', '', '0', no_values=None, _iter_req_id="uuid")
269+
[a async for a in AsyncScanCommands().zscan_iter("")]
270+
mock_execute_command.assert_called_with('ZSCAN', '', '0', score_cast_func=ANY, _iter_req_id="uuid")

0 commit comments

Comments
 (0)