Skip to content

Commit

Permalink
fix: Add session retries to constructor to avoid starting new connect…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
staticf0x committed Jan 18, 2024
1 parent 071ba10 commit 61901a7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions coregio/registry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ def __init__(
self._original_url = url
self.docker_cfg = docker_cfg

self.session = session or requests.Session()
if session:
self.session = session
else:
self.session = requests.Session()
utils.add_session_retries(self.session)

self.proxy = proxy

self.auth_header = None
Expand Down Expand Up @@ -196,7 +201,6 @@ def _get_session(self, auth_class: Callable[[Any], Any]) -> requests.Session:
auth_token, proxy=self.proxy
)
self.session.auth = self._auth_session_cache[auth_class]
utils.add_session_retries(self.session)

return self.session

Expand Down
15 changes: 15 additions & 0 deletions tests/test_registry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
from coregio.registry_api import ContainerRegistry


def test_init_new_session():
registry_api = ContainerRegistry(url="fake_url")
adapter = registry_api.session.adapters["https://"]

assert adapter.max_retries.total == 10


def test_init_pass_session():
session = requests.Session()
registry_api = ContainerRegistry(url="fake_url", session=session)
adapter = registry_api.session.adapters["https://"]

assert adapter.max_retries.total == 0


@pytest.mark.parametrize(
["url", "expected_url"],
[
Expand Down

0 comments on commit 61901a7

Please sign in to comment.