Skip to content

Commit ed2b539

Browse files
committed
add tests for all scan iter family
1 parent 8081e03 commit ed2b539

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
@@ -3068,7 +3068,7 @@ def sscan(
30683068
pieces.extend([b"MATCH", match])
30693069
if count is not None:
30703070
pieces.extend([b"COUNT", count])
3071-
return self.execute_command("SSCAN", *pieces,)
3071+
return self.execute_command("SSCAN", *pieces, **kwargs)
30723072

30733073
def sscan_iter(
30743074
self,
@@ -3293,11 +3293,7 @@ async def hscan_iter(
32933293
cursor = "0"
32943294
while cursor != 0:
32953295
cursor, data = await self.hscan(
3296-
<<<<<<< HEAD
3297-
name, cursor=cursor, match=match, count=count, no_values=no_values
3298-
=======
3299-
name, cursor=cursor, match=match, count=count, _iter_req_id=iter_req_id
3300-
>>>>>>> 39aaec6 (fix scan iter command issued to different replicas)
3296+
name, cursor=cursor, match=match, count=count, no_values=no_values, _iter_req_id=iter_req_id
33013297
)
33023298
if no_values:
33033299
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)