Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry on timeout #54

Merged
merged 4 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ The simplest way to hit the ground running if you want to contribute with code i

Launch a python container
```shell
localhost$ docker run --rm -it -v $(pwd):$(pwd) -w $(pwd) python:3.7-stretch bash
localhost$ docker run --rm -it -v $(pwd):$(pwd) -w $(pwd) python:3.11-slim-bullseye bash
```

Install the project and test dependencies in developer mode
Expand Down
7 changes: 5 additions & 2 deletions gordian/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _set_target_branch(self, target_branch, source_branch=None):
self.branch_name = f"refs/heads/{datetime.datetime.now().strftime('%Y-%m-%d-%H%M%S.%f')}"
self.source_branch = self.target_ref

@retry(GithubException, tries=3, delay=1, backoff=2)
@retry((GithubException, TimeoutError), tries=3, delay=1, backoff=2)
def _get_repo_contents(self, path):
try:
logger.debug(f'Fetching repo contents {path}...')
Expand All @@ -135,6 +135,9 @@ def _get_repo_contents(self, path):
if e.status == 404:
raise e
logger.info(f'Error fetching repo contents: {e}')
except TimeoutError as e:
logger.info(f'Error fetching repo contents: {e}')
raise e

@retry(GithubException, tries=3, delay=1, backoff=2)
def _make_branch(self):
Expand Down Expand Up @@ -248,6 +251,6 @@ def _get_new_version(self):
elif self.semver_label == 'patch':
patch = str(int(patch) + 1)
self.new_version = '.'.join([major, minor, patch])

def get_github_client(self):
return self._github
20 changes: 20 additions & 0 deletions tests/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,23 @@ def test__get_github_client(self):

self.assertIsNotNone(repo.get_github_client())
self.assertEqual(repo.get_github_client(), self.mock_git)

def test_get_repo_contents_timeout_error(self):
self.repo._set_target_branch('target')
self.repo.files = []
self.repo._source_repo = MagicMock()
self.repo._source_repo.get_contents.side_effect = TimeoutError('Read Timeout')
with pytest.raises(Exception) as context:
self.repo._get_repo_contents(path='test/afile.txt')
assert "Read Timeout" in str(context.value)
self.repo._source_repo.get_contents.assert_has_calls([call('test/afile.txt', 'target'), call('test/afile.txt', 'target'), call('test/afile.txt', 'target')])


def test_get_repo_contents(self):
self.repo._set_target_branch('target')
self.repo.files = []
self.repo._source_repo = MagicMock()
repository_file = MagicMock(path='test/afile.txt', type='not_dir')
self.repo._source_repo.get_contents.side_effect = [repository_file]
self.repo._get_repo_contents(path='test/afile.txt')
self.repo._source_repo.get_contents.assert_has_calls([call('test/afile.txt', 'target')])
Loading