Skip to content

Commit

Permalink
Add assertions and fix retryer
Browse files Browse the repository at this point in the history
  • Loading branch information
hexoul committed Oct 15, 2024
1 parent f9db9fb commit 9fba822
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion centraldogma/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def __init__(
max_keepalive_connections: int = 2,
**configs,
):
assert retries >= 0, "retries must be greater than or equal to zero"
assert max_connections > 0, "max_connections must be greater than zero"
assert (
max_keepalive_connections > 0
), "max_keepalive_connections must be greater than zero"

base_url = base_url[:-1] if base_url[-1] == "/" else base_url

for key in ["transport", "limits"]:
Expand Down Expand Up @@ -61,7 +67,7 @@ def request(
**kwargs,
) -> Union[Response, T]:
kwargs = self._set_request_headers(method, **kwargs)
retryer = Retrying(stop=stop_after_attempt(self.retries), reraise=True)
retryer = Retrying(stop=stop_after_attempt(self.retries + 1), reraise=True)
return retryer(self._request, method, path, handler, **kwargs)

def _set_request_headers(self, method: str, **kwargs) -> Dict:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from centraldogma.query import Query
from centraldogma.watcher import Watcher, Latest

dogma = Dogma()
dogma = Dogma(retries=3)
project_name = "TestProject"
repo_name = "TestRepository"

Expand Down
4 changes: 2 additions & 2 deletions tests/test_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_get_with_retry_by_response(respx_mock):
side_effect=[Response(503), Response(404), Response(200)],
)

retry_client = BaseClient(base_url, "token", retries=3)
retry_client = BaseClient(base_url, "token", retries=2)
retry_client.request("get", "/path", handler=ok_handler)

assert route.called
Expand All @@ -142,7 +142,7 @@ def test_get_with_retry_by_client(respx_mock):
side_effect=[ConnectError, ConnectError, NetworkError, Response(200)],
)

retry_client = BaseClient(base_url, "token", retries=5)
retry_client = BaseClient(base_url, "token", retries=10)
retry_client.request("get", "/path", handler=ok_handler)

assert route.called
Expand Down

0 comments on commit 9fba822

Please sign in to comment.