diff options
author | Tobias Henkel <tobias.henkel@bmw-carit.de> | 2018-06-13 16:41:56 +0200 |
---|---|---|
committer | Tobias Henkel <tobias.henkel@bmw.de> | 2018-11-22 19:40:27 +0100 |
commit | f312bda11890d0bf61d08eaa9f4473bd783864f2 (patch) | |
tree | 2d9ce0f24e95193d1eaf35a2a678c4b6eb0240da /tests/fakegithub.py | |
parent | bc136cb40e7215f790fd40f2121ba4c8a6552c94 (diff) | |
download | zuul-f312bda11890d0bf61d08eaa9f4473bd783864f2.tar.gz |
Retry queries for commits
When a pull_request event arrives we also get the commit statuses
which are attached to the commit object. Sometimes the commit is not
yet queryable and we get a 404 [1]. In this case we need to retry the
query. In the future we probably want to use that as a feedback
mechanism of a dynamic event delay.
[1] Trace
2018-06-13 11:49:11,881 ERROR zuul.GithubEventConnector: Exception moving GitHub event:
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/zuul/driver/github/githubconnection.py", line 391, in run
self._handleEvent()
File "/usr/lib/python3.6/site-packages/zuul/driver/github/githubconnection.py", line 226, in _handleEvent
refresh=True)
File "/usr/lib/python3.6/site-packages/zuul/driver/github/githubconnection.py", line 751, in _getChange
self._updateChange(change)
File "/usr/lib/python3.6/site-packages/zuul/driver/github/githubconnection.py", line 837, in _updateChange
change.patchset)
File "/usr/lib/python3.6/site-packages/zuul/driver/github/githubconnection.py", line 1226, in _get_statuses
for status in self.getCommitStatuses(project.name, sha):
File "/usr/lib/python3.6/site-packages/zuul/driver/github/githubconnection.py", line 1171, in getCommitStatuses
commit = repository.commit(sha)
File "/usr/lib/python3.6/site-packages/github3/repos/repo.py", line 342, in commit
json = self._json(self._get(url), 200)
File "/usr/lib/python3.6/site-packages/github3/models.py", line 156, in _json
raise exceptions.error_for(response)
github3.exceptions.NotFoundError: 404 Not Found
Change-Id: I5cc6d95ed18148657d9e5a8d132a8e43f385771d
Diffstat (limited to 'tests/fakegithub.py')
-rw-r--r-- | tests/fakegithub.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/fakegithub.py b/tests/fakegithub.py index 6b951ef51..df34c694b 100644 --- a/tests/fakegithub.py +++ b/tests/fakegithub.py @@ -14,6 +14,7 @@ # License for the specific language governing permissions and limitations # under the License. +import github3.exceptions import re FAKE_BASE_URL = 'https://example.com/api/v3/' @@ -82,6 +83,9 @@ class FakeRepository(object): self.data = data self.name = name + # fail the next commit requests with 404 + self.fail_not_found = 0 + def branches(self, protected=False): if protected: # simulate there is no protected branch @@ -121,6 +125,25 @@ class FakeRepository(object): commit.set_status(state, url, description, context, user) def commit(self, sha): + + if self.fail_not_found > 0: + self.fail_not_found -= 1 + + class Response: + status_code = 0 + message = '' + + def json(self): + return { + 'message': self.message + } + + resp = Response() + resp.status_code = 404 + resp.message = 'Not Found' + + raise github3.exceptions.NotFoundError(resp) + commit = self._commits.get(sha, None) if commit is None: commit = FakeCommit(sha) |