|
1 | 1 | import socket
|
2 | 2 | from typing import Tuple
|
3 |
| -from unittest.mock import AsyncMock |
| 3 | +from unittest.mock import AsyncMock, ANY |
4 | 4 |
|
5 | 5 | import pytest
|
6 | 6 | import pytest_asyncio
|
| 7 | +import uuid |
7 | 8 | from redis.asyncio.retry import Retry
|
| 9 | +from redis.commands.core import AsyncScanCommands |
8 | 10 | from redis.asyncio.sentinel import (
|
9 | 11 | Sentinel,
|
10 | 12 | SentinelConnectionPool,
|
@@ -244,3 +246,25 @@ async def test_connects_to_same_address_if_no_iter_req_id_master(
|
244 | 246 | await connection_pool_master_mock.get_connection("ANY_COMMAND"),
|
245 | 247 | connection_for_req_1,
|
246 | 248 | )
|
| 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