Skip to content

Commit 1738f9a

Browse files
committed
Adjust NoopLifespan to return EstablishedConnectionResult and update tests accordingly
1 parent 349f542 commit 1738f9a

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

packages/stompman/test_stompman/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import stompman
99
from polyfactory.factories.dataclass_factory import DataclassFactory
1010
from stompman.connection import AbstractConnection
11-
from stompman.connection_lifespan import AbstractConnectionLifespan
11+
from stompman.connection_lifespan import AbstractConnectionLifespan, EstablishedConnectionResult
1212
from stompman.connection_manager import ConnectionManager
1313

1414

@@ -59,7 +59,9 @@ class NoopLifespan(AbstractConnectionLifespan):
5959
connection: AbstractConnection
6060
connection_parameters: stompman.ConnectionParameters
6161

62-
async def enter(self) -> stompman.StompProtocolConnectionIssue | None: ...
62+
async def enter(self) -> EstablishedConnectionResult | stompman.StompProtocolConnectionIssue:
63+
return EstablishedConnectionResult(server_heartbeat=stompman.Heartbeat(1000, 1000))
64+
6365
async def exit(self) -> None: ...
6466

6567

@@ -76,6 +78,7 @@ class EnrichedConnectionManager(ConnectionManager):
7678
read_max_chunk_size: int = 5
7779
write_retry_attempts: int = 3
7880
ssl: Literal[True] | SSLContext | None = None
81+
check_server_alive_interval_factor: int = 3
7982

8083

8184
DataclassType = TypeVar("DataclassType")

packages/stompman/test_stompman/test_connection_manager.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
ErrorFrame,
1515
FailedAllConnectAttemptsError,
1616
FailedAllWriteAttemptsError,
17+
Heartbeat,
1718
MessageFrame,
1819
)
20+
from stompman.connection_lifespan import EstablishedConnectionResult
1921
from stompman.connection_manager import ActiveConnectionState
2022

21-
from test_stompman.conftest import BaseMockConnection, EnrichedConnectionManager, NoopLifespan, build_dataclass
23+
from test_stompman.conftest import BaseMockConnection, EnrichedConnectionManager, build_dataclass
2224

2325
pytestmark = [pytest.mark.anyio, pytest.mark.usefixtures("mock_sleep")]
2426

@@ -110,8 +112,7 @@ async def connect(
110112
)
111113
active_connection_state = await manager._create_connection_to_any_server()
112114
assert active_connection_state
113-
assert isinstance(active_connection_state.lifespan, NoopLifespan)
114-
assert active_connection_state.lifespan.connection_parameters == successful_server
115+
assert active_connection_state[1] == successful_server
115116

116117

117118
async def test_connect_to_any_server_fails() -> None:
@@ -169,7 +170,8 @@ class MockConnection(BaseMockConnection):
169170

170171

171172
async def test_get_active_connection_state_ok_concurrent() -> None:
172-
enter = mock.AsyncMock(return_value=None)
173+
server_heartbeat = build_dataclass(Heartbeat)
174+
enter = mock.AsyncMock(return_value=EstablishedConnectionResult(server_heartbeat=server_heartbeat))
173175
lifespan_factory = mock.Mock(return_value=mock.Mock(enter=enter))
174176
manager = EnrichedConnectionManager(lifespan_factory=lifespan_factory, connection_class=BaseMockConnection)
175177

@@ -185,7 +187,9 @@ async def test_get_active_connection_state_ok_concurrent() -> None:
185187
== second_state
186188
== third_state
187189
== fourth_state
188-
== ActiveConnectionState(connection=BaseMockConnection(), lifespan=lifespan_factory.return_value)
190+
== ActiveConnectionState(
191+
connection=BaseMockConnection(), lifespan=lifespan_factory.return_value, server_heartbeat=server_heartbeat
192+
)
189193
)
190194
assert first_state is second_state is third_state is fourth_state
191195

0 commit comments

Comments
 (0)