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

Fix test assertion in test_wrap_method_with_overriding_retry_deadline #4131

Merged
merged 2 commits into from
Oct 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 22 additions & 3 deletions core/tests/unit/api_core/gapic/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import datetime

import mock

from google.api.core import exceptions
Expand All @@ -21,6 +23,14 @@
import google.api.core.page_iterator


def _utcnow_monotonic():
curr_value = datetime.datetime.min
delta = datetime.timedelta(seconds=0.5)
while True:
yield curr_value
curr_value += delta


def test_wrap_method_basic():
method = mock.Mock(spec=['__call__'], return_value=42)

Expand Down Expand Up @@ -139,10 +149,14 @@ def test_wrap_method_with_overriding_retry_and_timeout(unusued_sleep):


@mock.patch('time.sleep')
def test_wrap_method_with_overriding_retry_deadline(unusued_sleep):
@mock.patch(
'google.api.core.helpers.datetime_helpers.utcnow',
side_effect=_utcnow_monotonic(),
autospec=True)
def test_wrap_method_with_overriding_retry_deadline(utcnow, unused_sleep):
method = mock.Mock(
spec=['__call__'],
side_effect=([exceptions.InternalServerError(None)] * 3) + [42]
side_effect=([exceptions.InternalServerError(None)] * 4) + [42]
)
default_retry = retry.Retry()
default_timeout = timeout.ExponentialTimeout(deadline=60)
Expand All @@ -156,7 +170,12 @@ def test_wrap_method_with_overriding_retry_deadline(unusued_sleep):

assert result == 42
timeout_args = [call[1]['timeout'] for call in method.call_args_list]
assert timeout_args == [5, 10, 20, 29]
assert timeout_args == [5.0, 10.0, 20.0, 26.0, 25.0]
assert utcnow.call_count == (
1 + # First to set the deadline.
5 + # One for each min(timeout, maximum, (DEADLINE - NOW).seconds)
5

This comment was marked as spam.

)


def test_wrap_method_with_overriding_timeout_as_a_number():
Expand Down