|
1 | 1 | import asyncio
|
2 | 2 | from collections.abc import AsyncGenerator, Coroutine
|
3 |
| -from functools import partial |
4 | 3 | from typing import Any
|
5 | 4 | from unittest import mock
|
6 | 5 |
|
|
17 | 16 | DisconnectFrame,
|
18 | 17 | ErrorFrame,
|
19 | 18 | FailedAllConnectAttemptsError,
|
20 |
| - HeartbeatFrame, |
21 | 19 | ReceiptFrame,
|
22 | 20 | UnsupportedProtocolVersion,
|
23 | 21 | )
|
@@ -156,58 +154,6 @@ async def mock_sleep(delay: float) -> None:
|
156 | 154 | assert write_heartbeat_mock.mock_calls == [mock.call(), mock.call(), mock.call()]
|
157 | 155 |
|
158 | 156 |
|
159 |
| -async def test_client_on_heartbeat_none(monkeypatch: pytest.MonkeyPatch) -> None: |
160 |
| - real_sleep = asyncio.sleep |
161 |
| - monkeypatch.setattr("asyncio.sleep", partial(asyncio.sleep, 0)) |
162 |
| - connection_class, _ = create_spying_connection( |
163 |
| - *get_read_frames_with_lifespan( |
164 |
| - [build_dataclass(HeartbeatFrame), build_dataclass(HeartbeatFrame), build_dataclass(HeartbeatFrame)] |
165 |
| - ) |
166 |
| - ) |
167 |
| - |
168 |
| - async with EnrichedClient(connection_class=connection_class, on_heartbeat=None): |
169 |
| - await real_sleep(0) |
170 |
| - await real_sleep(0) |
171 |
| - await real_sleep(0) |
172 |
| - |
173 |
| - |
174 |
| -async def test_client_on_heartbeat_sync(monkeypatch: pytest.MonkeyPatch) -> None: |
175 |
| - real_sleep = asyncio.sleep |
176 |
| - monkeypatch.setattr("asyncio.sleep", partial(asyncio.sleep, 0)) |
177 |
| - connection_class, _ = create_spying_connection( |
178 |
| - *get_read_frames_with_lifespan( |
179 |
| - [build_dataclass(HeartbeatFrame), build_dataclass(HeartbeatFrame), build_dataclass(HeartbeatFrame)] |
180 |
| - ) |
181 |
| - ) |
182 |
| - on_heartbeat_mock = mock.Mock() |
183 |
| - |
184 |
| - async with EnrichedClient(connection_class=connection_class, on_heartbeat=on_heartbeat_mock): |
185 |
| - await real_sleep(0) |
186 |
| - await real_sleep(0) |
187 |
| - await real_sleep(0) |
188 |
| - |
189 |
| - assert on_heartbeat_mock.mock_calls == [mock.call(), mock.call(), mock.call()] |
190 |
| - |
191 |
| - |
192 |
| -async def test_client_on_heartbeat_async(monkeypatch: pytest.MonkeyPatch) -> None: |
193 |
| - real_sleep = asyncio.sleep |
194 |
| - monkeypatch.setattr("asyncio.sleep", partial(asyncio.sleep, 0)) |
195 |
| - connection_class, _ = create_spying_connection( |
196 |
| - *get_read_frames_with_lifespan( |
197 |
| - [build_dataclass(HeartbeatFrame), build_dataclass(HeartbeatFrame), build_dataclass(HeartbeatFrame)] |
198 |
| - ) |
199 |
| - ) |
200 |
| - on_heartbeat_mock = mock.AsyncMock() |
201 |
| - |
202 |
| - async with EnrichedClient(connection_class=connection_class, on_heartbeat=on_heartbeat_mock): |
203 |
| - await real_sleep(0) |
204 |
| - await real_sleep(0) |
205 |
| - await real_sleep(0) |
206 |
| - |
207 |
| - assert on_heartbeat_mock.await_count == 3 # noqa: PLR2004 |
208 |
| - assert on_heartbeat_mock.mock_calls == [mock.call.__bool__(), mock.call(), mock.call(), mock.call()] |
209 |
| - |
210 |
| - |
211 | 157 | def test_make_receipt_id(monkeypatch: pytest.MonkeyPatch) -> None:
|
212 | 158 | monkeypatch.undo()
|
213 | 159 | stompman.connection_lifespan._make_receipt_id()
|
0 commit comments