From 129520e5119a55509957c5438ba9aa51611cf2ce Mon Sep 17 00:00:00 2001 From: mroloux Date: Mon, 26 Oct 2026 09:58:29 +0100 Subject: [PATCH] Raise default timeout to 30s read, 10s connect, and make it configurable Co-Authored-By: Claude Sonnet 5.5 --- README.md | 13 +++++++++++++ seatsio/client.py | 4 ++-- seatsio/httpClient.py | 2 +- tests/testTimeout.py | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 tests/testTimeout.py diff --git a/README.md b/README.md index 90ab733..1895036 100644 --- a/README.md +++ b/README.md @@ -207,3 +207,16 @@ client = seatsio.Client(seatsio.Region.EU(), secret_key="my-workspace-secret-key ``` Passing in 0 disables exponential backoff completely. In that case, the client will never retry a failed request. + +## Timeouts + +By default, the client waits up to 10 seconds to connect to the server, and up to 30 seconds for the server to respond. + +To change this, pass a `timeout` when creating the `Client`. It accepts a single number of seconds, or a `(connect, read)` tuple: + +```python +import seatsio +client = seatsio.Client(seatsio.Region.EU(), secret_key="my-workspace-secret-key", timeout=(10, 60)) +``` + +Requests that time out are not retried. diff --git a/seatsio/client.py b/seatsio/client.py index 781990a..d1386b0 100644 --- a/seatsio/client.py +++ b/seatsio/client.py @@ -10,10 +10,10 @@ class Client: - def __init__(self, region, secret_key, workspace_key=None, max_retries=5): + def __init__(self, region, secret_key, workspace_key=None, max_retries=5, timeout=(10, 30)): base_url = region.url self.base_url = base_url - self.http_client = HttpClient(base_url, secret_key, workspace_key, max_retries) + self.http_client = HttpClient(base_url, secret_key, workspace_key, max_retries, timeout) self.charts = ChartsClient(self.http_client) self.events = EventsClient(self.http_client) self.seasons = SeasonsClient(self.http_client, self) diff --git a/seatsio/httpClient.py b/seatsio/httpClient.py index 16e2809..9f7897c 100644 --- a/seatsio/httpClient.py +++ b/seatsio/httpClient.py @@ -12,7 +12,7 @@ def handle_error(request, response): class HttpClient: - def __init__(self, base_url, secret_key, workspace_key, max_retries, timeout=10): + def __init__(self, base_url, secret_key, workspace_key, max_retries, timeout=(10, 30)): self.base_url = base_url self.secret_key = secret_key self.workspace_key = workspace_key diff --git a/tests/testTimeout.py b/tests/testTimeout.py new file mode 100644 index 0000000..e1d944f --- /dev/null +++ b/tests/testTimeout.py @@ -0,0 +1,36 @@ +import unittest +from unittest.mock import patch, MagicMock + +import seatsio +from seatsio.httpClient import HttpClient +from tests.util.asserts import assert_that + + +def ok_response(): + response = MagicMock() + response.status_code = 200 + response.json.return_value = {} + return response + + +class TimeoutTest(unittest.TestCase): + + def test_default_timeout(self): + with patch("seatsio.httpClient.requests.get", return_value=ok_response()) as get: + HttpClient("http://localhost", "aSecretKey", None, 5).url("/ping").get() + assert_that(get.call_args.kwargs["timeout"]).is_equal_to((10, 30)) + + def test_client_default_timeout(self): + with patch("seatsio.httpClient.requests.get", return_value=ok_response()) as get: + seatsio.Client(seatsio.Region.EU(), "aSecretKey").http_client.url("/ping").get() + assert_that(get.call_args.kwargs["timeout"]).is_equal_to((10, 30)) + + def test_client_custom_timeout(self): + with patch("seatsio.httpClient.requests.get", return_value=ok_response()) as get: + seatsio.Client(seatsio.Region.EU(), "aSecretKey", timeout=(5, 60)).http_client.url("/ping").get() + assert_that(get.call_args.kwargs["timeout"]).is_equal_to((5, 60)) + + def test_client_custom_timeout_applies_to_post(self): + with patch("seatsio.httpClient.requests.post", return_value=ok_response()) as post: + seatsio.Client(seatsio.Region.EU(), "aSecretKey", timeout=45).http_client.url("/ping").post() + assert_that(post.call_args.kwargs["timeout"]).is_equal_to(45)