Skip to content

Commit 2115edb

Browse files
authored
test: Make sure we actually test the python timeouts (#175)
During the test, I also discovered that we have to force `Retry(read=0)`, otherwise it will fail trying to rewind the zstd stream.
1 parent c26c39a commit 2115edb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

clients/python/src/objectstore_client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(
5151
self._usecase = usecase
5252

5353
# We only retry connection problems, as we cannot rewind our compression stream.
54-
self._retries = retries or urllib3.Retry(connect=3, redirect=5)
54+
self._retries = retries or urllib3.Retry(connect=3, redirect=5, read=0)
5555
# The read timeout is defined to be "between consecutive read operations",
5656
# which should mean one chunk of the response, with a large response being
5757
# split into multiple chunks.

clients/python/tests/test_e2e.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,17 @@ def test_full_cycle(server_url: str) -> None:
105105

106106
with pytest.raises(ClientError, check=lambda e: e.status == 404):
107107
client.get(object_key)
108+
109+
110+
def test_connect_timeout() -> None:
111+
# this server accepts the connection
112+
# (even though the backlog is 0 and we never call `accept`),
113+
# but will never reply with anything, thus causing a read timeout
114+
s = socket.create_server(("127.0.0.1", 0), backlog=0)
115+
addr = s.getsockname()
116+
url = f"http://127.0.0.1:{addr[1]}"
117+
118+
timeout = urllib3.Timeout(connect=0.05, read=0.05) # 50ms
119+
client = ClientBuilder(url, "test-usecase", timeout=timeout).for_organization(12345)
120+
with pytest.raises(urllib3.exceptions.MaxRetryError):
121+
client.put(b"foo")

0 commit comments

Comments
 (0)