Skip to content

Commit ef8d9e3

Browse files
committed
Add test for connection aliveness and remove duplicate from test_connection_manager
1 parent 58daaa7 commit ef8d9e3

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import time
2+
3+
import pytest
4+
from stompman import Client, ConnectedFrame, ReceiptFrame
5+
6+
from test_stompman.conftest import EnrichedClient, build_dataclass, create_spying_connection
7+
8+
pytestmark = [pytest.mark.anyio, pytest.mark.usefixtures("mock_sleep")]
9+
10+
11+
@pytest.mark.parametrize("is_alive", [True, False])
12+
async def test_connection_alive(is_alive: bool) -> None: # noqa: FBT001
13+
connection_class, _ = create_spying_connection(
14+
[ConnectedFrame(headers={"version": Client.PROTOCOL_VERSION, "heart-beat": "1000,1000"})],
15+
[],
16+
[build_dataclass(ReceiptFrame)],
17+
)
18+
client = await EnrichedClient(connection_class=connection_class).__aenter__()
19+
assert client._connection_manager._active_connection_state
20+
client._connection_manager._active_connection_state.connection.last_read_time = time.time() - 1 + is_alive
21+
assert client.is_alive() == is_alive

packages/stompman/test_stompman/test_connection_manager.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,3 @@ class MockConnection(BaseMockConnection):
355355
async def test_maybe_write_frame_ok() -> None:
356356
async with EnrichedConnectionManager(connection_class=BaseMockConnection) as manager:
357357
assert await manager.maybe_write_frame(build_dataclass(ConnectFrame))
358-
359-
360-
@pytest.mark.parametrize("is_alive", [True, False])
361-
async def test_connection_alive(is_alive: bool) -> None: # noqa: FBT001
362-
connection_class, _ = create_spying_connection(
363-
[ConnectedFrame(headers={"version": Client.PROTOCOL_VERSION, "heart-beat": "1000,1000"})],
364-
[],
365-
[build_dataclass(ReceiptFrame)],
366-
)
367-
connection_manager = await EnrichedConnectionManager(connection_class=connection_class).__aenter__()
368-
assert connection_manager._active_connection_state
369-
connection_manager._active_connection_state.connection.last_read_time = time.time() - 1 + is_alive
370-
assert connection_manager._active_connection_state.is_alive() == is_alive

0 commit comments

Comments
 (0)