Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Feb 23, 2026. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 96
feat(api-core): pass retry from result() to done()#9
Merged
gcf-merge-on-green
merged 12 commits into
googleapis:master
from
MaxxleLLC:retry_into_doneOct 16, 2020
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
512a65f
feat(api-core): pass retry from result() to done()
a5288b2
fix tests
b6a0655
Merge branch 'master' into retry_into_done
busunkim96 3c58c28
Merge branch 'master' into retry_into_done
e8c1de4
pass retry into done() only if it is not default
0f145ac
Merge branch 'master' into retry_into_done
tswast 812a2e5
add more unit tests
f6b1749
Merge branch 'retry_into_done' of https://github.com/q-logic/python-a…
6e411ec
use super() in the overriden result() method
0c17181
fix super() function call for py-2.x
2b21471
add kwargs guard
57468f8
Merge branch 'master' into retry_into_done
tswast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -19,7 +19,7 @@ | ||
| import mock | ||
| import pytest | ||
| from google.api_core import exceptions | ||
| from google.api_core import exceptions, retry | ||
| from google.api_core.future import polling | ||
| @@ -43,6 +43,8 @@ def test_polling_future_constructor(): | ||
| assert not future.cancelled() | ||
| assert future.running() | ||
| assert future.cancel() | ||
| with mock.patch.object(future, "done", return_value=True): | ||
| future.result() | ||
| def test_set_result(): | ||
| @@ -87,7 +89,7 @@ def __init__(self): | ||
| self.poll_count = 0 | ||
| self.event = threading.Event() | ||
| def done(self): | ||
| def done(self, retry=polling.DEFAULT_RETRY): | ||
| self.poll_count += 1 | ||
| self.event.wait() | ||
| self.set_result(42) | ||
| @@ -108,7 +110,7 @@ def test_result_with_polling(): | ||
| class PollingFutureImplTimeout(PollingFutureImplWithPoll): | ||
| def done(self): | ||
| def done(self, retry=polling.DEFAULT_RETRY): | ||
| time.sleep(1) | ||
| return False | ||
| @@ -130,7 +132,7 @@ def __init__(self, errors): | ||
| super(PollingFutureImplTransient, self).__init__() | ||
| self._errors = errors | ||
| def done(self): | ||
| def done(self, retry=polling.DEFAULT_RETRY): | ||
| if self._errors: | ||
| error, self._errors = self._errors[0], self._errors[1:] | ||
| raise error("testing") | ||
| @@ -192,3 +194,49 @@ def test_double_callback_background_thread(): | ||
| assert future.poll_count == 1 | ||
| callback.assert_called_once_with(future) | ||
| callback2.assert_called_once_with(future) | ||
| class PollingFutureImplWithoutRetry(PollingFutureImpl): | ||
| def done(self): | ||
| return True | ||
IlyaFaer marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| def result(self): | ||
| return super(PollingFutureImplWithoutRetry, self).result() | ||
| def _blocking_poll(self, timeout): | ||
| return super(PollingFutureImplWithoutRetry, self)._blocking_poll( | ||
| timeout=timeout | ||
| ) | ||
| class PollingFutureImplWith_done_or_raise(PollingFutureImpl): | ||
| def done(self): | ||
| return True | ||
IlyaFaer marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| def _done_or_raise(self): | ||
| return super(PollingFutureImplWith_done_or_raise, self)._done_or_raise() | ||
| def test_polling_future_without_retry(): | ||
| custom_retry = retry.Retry( | ||
| predicate=retry.if_exception_type(exceptions.TooManyRequests) | ||
| ) | ||
| future = PollingFutureImplWithoutRetry() | ||
| assert future.done() | ||
| assert future.running() | ||
| assert future.result() is None | ||
| with mock.patch.object(future, "done") as done_mock: | ||
| future._done_or_raise() | ||
| done_mock.assert_called_once_with() | ||
| with mock.patch.object(future, "done") as done_mock: | ||
| future._done_or_raise(retry=custom_retry) | ||
| done_mock.assert_called_once_with(retry=custom_retry) | ||
| def test_polling_future_with__done_or_raise(): | ||
| future = PollingFutureImplWith_done_or_raise() | ||
| assert future.done() | ||
| assert future.running() | ||
| assert future.result() is None | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.