Skip to content

Commit ef129ee

Browse files
authored
Remove unneeded read_timeout (#123)
1 parent 7859a58 commit ef129ee

File tree

9 files changed

+10
-36
lines changed

9 files changed

+10
-36
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ async with stompman.Client(
3838
connect_timeout=2,
3939
connection_confirmation_timeout=2,
4040
disconnect_confirmation_timeout=2,
41-
read_timeout=2,
4241
write_retry_attempts=3,
4342
check_server_alive_interval_factor=3,
4443
) as client:
@@ -144,7 +143,7 @@ Also, I want to pointed out that:
144143

145144
- Protocol parsing is inspired by [aiostomp](https://github.com/pedrokiefer/aiostomp/blob/3449dcb53f43e5956ccc7662bb5b7d76bc6ef36b/aiostomp/protocol.py) (meaning: consumed by me and refactored from).
146145
- stompman is tested and used with [ActiveMQ Artemis](https://activemq.apache.org/components/artemis/) and [ActiveMQ Classic](https://activemq.apache.org/components/classic/).
147-
- Caveat: a message sent by a Stomp client is converted into a JMS `TextMessage`/`BytesMessage` based on the `content-length` header (see the docs [here](https://activemq.apache.org/components/classic/documentation/stomp)). In order to send a `TextMessage`, `Client.send` needs to be invoked with `add_content_length` header set to `False`
146+
- Caveat: a message sent by a Stomp client is converted into a JMS `TextMessage`/`BytesMessage` based on the `content-length` header (see the docs [here](https://activemq.apache.org/components/classic/documentation/stomp)). In order to send a `TextMessage`, `Client.send` needs to be invoked with `add_content_length` header set to `False`
148147
- Specification says that headers in CONNECT and CONNECTED frames shouldn't be escaped for backwards compatibility. stompman escapes headers in CONNECT frame (outcoming), but does not unescape headers in CONNECTED (outcoming).
149148

150149
### FastStream STOMP broker

conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import platform
12
from typing import cast
23

34
import pytest
@@ -24,6 +25,10 @@ def first_server_connection_parameters() -> stompman.ConnectionParameters:
2425
stompman.ConnectionParameters(host="127.0.0.1", port=9000, login="admin", passcode=":=123"),
2526
stompman.ConnectionParameters(host="127.0.0.1", port=9001, login="admin", passcode=":=123"),
2627
]
28+
if platform.platform() == "Linux" # TODO: fix tests with ActiveMQ Classic on Mac # noqa: FIX002, TD002, TD003
29+
else [
30+
stompman.ConnectionParameters(host="127.0.0.1", port=9000, login="admin", passcode=":=123"),
31+
],
2732
)
2833
def connection_parameters(request: pytest.FixtureRequest) -> stompman.ConnectionParameters:
2934
return cast("stompman.ConnectionParameters", request.param)

packages/stompman/stompman/client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class Client:
3636
connect_retry_attempts: int = 3
3737
connect_retry_interval: int = 1
3838
connect_timeout: int = 2
39-
read_timeout: int = 2
4039
read_max_chunk_size: int = 1024 * 1024
4140
write_retry_attempts: int = 3
4241
connection_confirmation_timeout: int = 2
@@ -69,7 +68,6 @@ def __post_init__(self) -> None:
6968
connect_retry_attempts=self.connect_retry_attempts,
7069
connect_retry_interval=self.connect_retry_interval,
7170
connect_timeout=self.connect_timeout,
72-
read_timeout=self.read_timeout,
7371
read_max_chunk_size=self.read_max_chunk_size,
7472
write_retry_attempts=self.write_retry_attempts,
7573
check_server_alive_interval_factor=self.check_server_alive_interval_factor,

packages/stompman/stompman/connection.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ async def connect(
2424
port: int,
2525
timeout: int,
2626
read_max_chunk_size: int,
27-
read_timeout: int,
2827
ssl: Literal[True] | SSLContext | None,
2928
) -> Self | None: ...
3029
async def close(self) -> None: ...
@@ -46,7 +45,6 @@ class Connection(AbstractConnection):
4645
reader: asyncio.StreamReader
4746
writer: asyncio.StreamWriter
4847
read_max_chunk_size: int
49-
read_timeout: int
5048
ssl: Literal[True] | SSLContext | None
5149

5250
@classmethod
@@ -57,7 +55,6 @@ async def connect(
5755
port: int,
5856
timeout: int,
5957
read_max_chunk_size: int,
60-
read_timeout: int,
6158
ssl: Literal[True] | SSLContext | None,
6259
) -> Self | None:
6360
try:
@@ -69,7 +66,6 @@ async def connect(
6966
reader=reader,
7067
writer=writer,
7168
read_max_chunk_size=read_max_chunk_size,
72-
read_timeout=read_timeout,
7369
ssl=ssl,
7470
)
7571

@@ -99,10 +95,8 @@ async def read_frames(self) -> AsyncGenerator[AnyServerFrame, None]:
9995
parser = FrameParser()
10096

10197
while True:
102-
with _reraise_connection_lost(ConnectionError, TimeoutError):
103-
raw_frames = await asyncio.wait_for(
104-
self._read_non_empty_bytes(self.read_max_chunk_size), timeout=self.read_timeout
105-
)
98+
with _reraise_connection_lost(ConnectionError):
99+
raw_frames = await self._read_non_empty_bytes(self.read_max_chunk_size)
106100
self.last_read_time = time.time()
107101

108102
for frame in cast("Iterator[AnyServerFrame]", parser.parse_frames_from_chunk(raw_frames)):

packages/stompman/stompman/connection_manager.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class ConnectionManager:
4646
connect_retry_interval: int
4747
connect_timeout: int
4848
ssl: Literal[True] | SSLContext | None
49-
read_timeout: int
5049
read_max_chunk_size: int
5150
write_retry_attempts: int
5251
check_server_alive_interval_factor: int
@@ -113,7 +112,6 @@ async def _create_connection_to_one_server(
113112
port=server.port,
114113
timeout=self.connect_timeout,
115114
read_max_chunk_size=self.read_max_chunk_size,
116-
read_timeout=self.read_timeout,
117115
ssl=self.ssl,
118116
):
119117
return (connection, server)

packages/stompman/test_stompman/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ async def connect(
3434
port: int,
3535
timeout: int,
3636
read_max_chunk_size: int,
37-
read_timeout: int,
3837
ssl: Literal[True] | SSLContext | None,
3938
) -> Self | None:
4039
return cls()
@@ -76,7 +75,6 @@ class EnrichedConnectionManager(ConnectionManager):
7675
connect_retry_attempts: int = 3
7776
connect_retry_interval: int = 1
7877
connect_timeout: int = 3
79-
read_timeout: int = 4
8078
read_max_chunk_size: int = 5
8179
write_retry_attempts: int = 3
8280
ssl: Literal[True] | SSLContext | None = None

packages/stompman/test_stompman/test_connection.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import asyncio
22
import socket
33
from collections.abc import Awaitable
4-
from functools import partial
54
from typing import Any
65
from unittest import mock
76

@@ -21,9 +20,7 @@
2120

2221

2322
async def make_connection() -> Connection | None:
24-
return await Connection.connect(
25-
host="localhost", port=12345, timeout=2, read_max_chunk_size=1024 * 1024, read_timeout=2, ssl=None
26-
)
23+
return await Connection.connect(host="localhost", port=12345, timeout=2, read_max_chunk_size=1024 * 1024, ssl=None)
2724

2825

2926
async def make_mocked_connection(monkeypatch: pytest.MonkeyPatch, reader: object, writer: object) -> Connection:
@@ -151,15 +148,6 @@ async def test_connection_connect_connection_error(monkeypatch: pytest.MonkeyPat
151148
assert not await make_connection()
152149

153150

154-
async def test_read_frames_timeout_error(monkeypatch: pytest.MonkeyPatch) -> None:
155-
connection = await make_mocked_connection(
156-
monkeypatch, mock.AsyncMock(read=partial(asyncio.sleep, 5)), mock.AsyncMock()
157-
)
158-
mock_wait_for(monkeypatch)
159-
with pytest.raises(ConnectionLostError):
160-
[frame async for frame in connection.read_frames()]
161-
162-
163151
async def test_read_frames_connection_error(monkeypatch: pytest.MonkeyPatch) -> None:
164152
connection = await make_mocked_connection(
165153
monkeypatch, mock.AsyncMock(read=mock.AsyncMock(side_effect=BrokenPipeError)), mock.AsyncMock()

packages/stompman/test_stompman/test_connection_manager.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ async def connect(
4242
port: int,
4343
timeout: int,
4444
read_max_chunk_size: int,
45-
read_timeout: int,
4645
ssl: Literal[True] | SSLContext | None,
4746
) -> Self | None:
4847
assert (host, port) == (manager.servers[0].host, manager.servers[0].port)
@@ -55,7 +54,6 @@ async def connect(
5554
port=port,
5655
timeout=timeout,
5756
read_max_chunk_size=read_max_chunk_size,
58-
read_timeout=read_timeout,
5957
ssl=ssl,
6058
)
6159
if attempts == ok_on_attempt
@@ -88,7 +86,6 @@ async def connect(
8886
port: int,
8987
timeout: int,
9088
read_max_chunk_size: int,
91-
read_timeout: int,
9289
ssl: Literal[True] | SSLContext | None,
9390
) -> Self | None:
9491
return (
@@ -97,7 +94,6 @@ async def connect(
9794
port=port,
9895
timeout=timeout,
9996
read_max_chunk_size=read_max_chunk_size,
100-
read_timeout=read_timeout,
10197
ssl=ssl,
10298
)
10399
if port == successful_server.port

packages/stompman/test_stompman/test_integration.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424

2525
@asynccontextmanager
2626
async def create_client(connection_parameters: stompman.ConnectionParameters) -> AsyncGenerator[stompman.Client, None]:
27-
async with stompman.Client(
28-
servers=[connection_parameters], read_timeout=10, connection_confirmation_timeout=10
29-
) as client:
27+
async with stompman.Client(servers=[connection_parameters], connection_confirmation_timeout=10) as client:
3028
yield client
3129

3230

0 commit comments

Comments
 (0)