Skip to content

Commit 378d6db

Browse files
committed
add tests for all scan iter family
1 parent 9a9f062 commit 378d6db

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

redis/commands/core.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,7 +3070,7 @@ def sscan(
30703070
pieces.extend([b"MATCH", match])
30713071
if count is not None:
30723072
pieces.extend([b"COUNT", count])
3073-
return self.execute_command("SSCAN", *pieces,)
3073+
return self.execute_command("SSCAN", *pieces, **kwargs)
30743074

30753075
def sscan_iter(
30763076
self,
@@ -3295,11 +3295,7 @@ async def hscan_iter(
32953295
cursor = "0"
32963296
while cursor != 0:
32973297
cursor, data = await self.hscan(
3298-
<<<<<<< HEAD
3299-
name, cursor=cursor, match=match, count=count, no_values=no_values
3300-
=======
3301-
name, cursor=cursor, match=match, count=count, _iter_req_id=iter_req_id
3302-
>>>>>>> 39aaec6 (fix scan iter command issued to different replicas)
3298+
name, cursor=cursor, match=match, count=count, no_values=no_values, _iter_req_id=iter_req_id
33033299
)
33043300
if no_values:
33053301
for it in data:

tests/test_asyncio/test_sentinel_managed_connection.py

Lines changed: 25 additions & 1 deletion
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)