Skip to content

Commit 830f6cf

Browse files
committed
Adjustments for heartbeat logging and connection manager logic
1 parent 1738f9a commit 830f6cf

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

packages/stompman/stompman/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ async def __aexit__(
109109
def _restart_heartbeat_tasks(self, server_heartbeat: Heartbeat) -> None:
110110
self._send_heartbeat_task.cancel()
111111
self._check_server_heartbeat_task.cancel()
112+
print(server_heartbeat)
112113
self._send_heartbeat_task = self._task_group.create_task(
113114
self._send_heartbeats_forever(server_heartbeat.want_to_receive_interval_ms)
114115
)

packages/stompman/stompman/connection_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from stompman.config import ConnectionParameters, Heartbeat
1010
from stompman.connection import AbstractConnection
11-
from stompman.connection_lifespan import EstablishedConnectionResult
1211
from stompman.errors import (
1312
AllServersUnavailable,
1413
AnyConnectionIssue,
@@ -85,6 +84,8 @@ async def _create_connection_to_any_server(self) -> tuple[AbstractConnection, Co
8584
return None
8685

8786
async def _connect_to_any_server(self) -> ActiveConnectionState | AnyConnectionIssue:
87+
from stompman.connection_lifespan import EstablishedConnectionResult # noqa: PLC0415
88+
8889
if not (connection_and_server := await self._create_connection_to_any_server()):
8990
return AllServersUnavailable(servers=self.servers, timeout=self.connect_timeout)
9091
connection, connection_parameters = connection_and_server

packages/stompman/test_stompman/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ async def read_frames() -> AsyncGenerator[stompman.AnyServerFrame, None]:
125125
"passcode": "passcode",
126126
},
127127
)
128-
CONNECTED_FRAME = stompman.ConnectedFrame(headers={"version": stompman.Client.PROTOCOL_VERSION, "heart-beat": "1,1"})
128+
CONNECTED_FRAME = stompman.ConnectedFrame(
129+
headers={"version": stompman.Client.PROTOCOL_VERSION, "heart-beat": "1000,1000"}
130+
)
129131

130132

131133
@pytest.fixture(autouse=True)

packages/stompman/test_stompman/test_connection_lifespan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ async def mock_sleep(delay: float) -> None:
152152
await real_sleep(0)
153153
await real_sleep(0)
154154

155-
assert sleep_calls == [0, 1, 1]
155+
assert sleep_calls == [0, 0, 1, 3, 1, 3]
156156
assert write_heartbeat_mock.mock_calls == [mock.call(), mock.call(), mock.call()]
157157

158158

packages/stompman/test_stompman/test_connection_manager.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class MockConnection(BaseMockConnection):
132132

133133

134134
async def test_get_active_connection_state_lifespan_flaky_ok() -> None:
135-
enter = mock.AsyncMock(side_effect=[ConnectionLostError, None])
135+
enter = mock.AsyncMock(side_effect=[ConnectionLostError, build_dataclass(EstablishedConnectionResult)])
136136
lifespan_factory = mock.Mock(return_value=mock.Mock(enter=enter))
137137
manager = EnrichedConnectionManager(lifespan_factory=lifespan_factory, connection_class=BaseMockConnection)
138138

@@ -206,7 +206,8 @@ async def test_connection_manager_context_lifespan_aexit_raises_connection_lost(
206206
async with EnrichedConnectionManager(
207207
lifespan_factory=mock.Mock(
208208
return_value=mock.Mock(
209-
enter=mock.AsyncMock(return_value=None), exit=mock.AsyncMock(side_effect=[ConnectionLostError])
209+
enter=mock.AsyncMock(return_value=build_dataclass(EstablishedConnectionResult)),
210+
exit=mock.AsyncMock(side_effect=[ConnectionLostError]),
210211
)
211212
),
212213
connection_class=BaseMockConnection,
@@ -222,7 +223,11 @@ class MockConnection(BaseMockConnection):
222223
close = connection_close
223224

224225
async with EnrichedConnectionManager(
225-
lifespan_factory=mock.Mock(return_value=mock.Mock(enter=mock.AsyncMock(return_value=None), exit=close)),
226+
lifespan_factory=mock.Mock(
227+
return_value=mock.Mock(
228+
enter=mock.AsyncMock(return_value=build_dataclass(EstablishedConnectionResult)), exit=close
229+
)
230+
),
226231
connection_class=MockConnection,
227232
):
228233
pass

0 commit comments

Comments
 (0)