|
1 | 1 | import socket
|
2 |
| -from typing import Tuple |
| 2 | +from typing import Iterator, Tuple |
3 | 3 |
|
4 | 4 | import pytest
|
5 | 5 | from redis.asyncio.retry import Retry
|
@@ -59,35 +59,46 @@ async def _connect_to_sentinel(self) -> None:
|
59 | 59 | self.host = f"host-{random.randint(0, 10)}"
|
60 | 60 | self.port = time.time()
|
61 | 61 |
|
| 62 | + async def connect_to(self, address: Tuple[str, int]) -> None: |
| 63 | + """ |
| 64 | + Do nothing, just mock. |
| 65 | + """ |
| 66 | + |
62 | 67 |
|
63 | 68 | @pytest.fixture()
|
64 |
| -def connection_pool_replica_mock() -> SentinelConnectionPool: |
| 69 | +def connection_pool_replica_mock() -> Iterator[SentinelConnectionPool]: |
65 | 70 | sentinel_manager = Sentinel([["master", 400]])
|
66 | 71 | # Give a random slave
|
67 | 72 | sentinel_manager.discover_slaves = mock.AsyncMock(return_value=["replica", 5000])
|
68 |
| - # Create connection pool with our mock connection object |
69 |
| - connection_pool = SentinelConnectionPool( |
70 |
| - "usasm", |
71 |
| - sentinel_manager, |
72 |
| - is_master=False, |
73 |
| - connection_class=SentinelManagedConnectionMock, |
74 |
| - ) |
75 |
| - return connection_pool |
| 73 | + with mock.patch( |
| 74 | + "redis._parsers._AsyncRESP2Parser.can_read_destructive", return_value=False |
| 75 | + ): |
| 76 | + # Create connection pool with our mock connection object |
| 77 | + connection_pool = SentinelConnectionPool( |
| 78 | + "usasm", |
| 79 | + sentinel_manager, |
| 80 | + is_master=False, |
| 81 | + connection_class=SentinelManagedConnectionMock, |
| 82 | + ) |
| 83 | + yield connection_pool |
76 | 84 |
|
77 | 85 |
|
78 | 86 | @pytest.fixture()
|
79 |
| -def connection_pool_master_mock() -> SentinelConnectionPool: |
| 87 | +def connection_pool_master_mock() -> Iterator[SentinelConnectionPool]: |
80 | 88 | sentinel_manager = Sentinel([["master", 400]])
|
81 | 89 | # Give a random slave
|
82 | 90 | sentinel_manager.discover_master = mock.AsyncMock(return_value=["replica", 5000])
|
83 |
| - # Create connection pool with our mock connection object |
84 |
| - connection_pool = SentinelConnectionPool( |
85 |
| - "usasm", |
86 |
| - sentinel_manager, |
87 |
| - is_master=True, |
88 |
| - connection_class=SentinelManagedConnectionMock, |
89 |
| - ) |
90 |
| - return connection_pool |
| 91 | + with mock.patch( |
| 92 | + "redis._parsers._AsyncRESP2Parser.can_read_destructive", return_value=False |
| 93 | + ): |
| 94 | + # Create connection pool with our mock connection object |
| 95 | + connection_pool = SentinelConnectionPool( |
| 96 | + "usasm", |
| 97 | + sentinel_manager, |
| 98 | + is_master=True, |
| 99 | + connection_class=SentinelManagedConnectionMock, |
| 100 | + ) |
| 101 | + yield connection_pool |
91 | 102 |
|
92 | 103 |
|
93 | 104 | def same_address(
|
|
0 commit comments