def _timeout_from_retry_config(retry_params):
    """Creates a ExponentialTimeout object given a gapic retry configuration.

    Args:
        retry_params (dict): The retry parameter values, for example::

            {
                "initial_retry_delay_millis": 1000,
                "retry_delay_multiplier": 2.5,
                "max_retry_delay_millis": 120000,
                "initial_rpc_timeout_millis": 120000,
                "rpc_timeout_multiplier": 1.0,
                "max_rpc_timeout_millis": 120000,
                "total_timeout_millis": 600000
            }

    Returns:
        google.api.core.retry.ExponentialTimeout: The default time object for
            the method.
    """
    return timeout.ExponentialTimeout(
        initial=(retry_params['initial_rpc_timeout_millis'] /
                 _MILLIS_PER_SECOND),
        maximum=(retry_params['max_rpc_timeout_millis'] / _MILLIS_PER_SECOND),
        multiplier=retry_params['rpc_timeout_multiplier'],
        deadline=(retry_params['total_timeout_millis'] / _MILLIS_PER_SECOND))
Exemple #2
0
 def test_with_timeout(self):
     original_timeout = timeout.ExponentialTimeout()
     timeout_ = original_timeout.with_deadline(42)
     assert original_timeout is not timeout_
     assert timeout_._initial == timeout._DEFAULT_INITIAL_TIMEOUT
     assert timeout_._maximum == timeout._DEFAULT_MAXIMUM_TIMEOUT
     assert timeout_._multiplier == timeout._DEFAULT_TIMEOUT_MULTIPLIER
     assert timeout_._deadline == 42
Exemple #3
0
    def test_apply_passthrough(self):
        target = mock.Mock(spec=['__call__', '__name__'], __name__='target')
        timeout_ = timeout.ExponentialTimeout(42.0, 100, 2)
        wrapped = timeout_(target)

        wrapped(1, 2, meep='moop')

        target.assert_called_once_with(1, 2, meep='moop', timeout=42.0)
Exemple #4
0
    def test_apply(self):
        target = mock.Mock(spec=['__call__', '__name__'], __name__='target')
        timeout_ = timeout.ExponentialTimeout(1, 10, 2)
        wrapped = timeout_(target)

        wrapped()
        target.assert_called_with(timeout=1)

        wrapped()
        target.assert_called_with(timeout=2)

        wrapped()
        target.assert_called_with(timeout=4)
def test_wrap_method_with_overriding_retry_deadline(unusued_sleep):
    method = mock.Mock(
        spec=['__call__'],
        side_effect=([exceptions.InternalServerError(None)] * 3) + [42])
    default_retry = retry.Retry()
    default_timeout = timeout.ExponentialTimeout(deadline=60)
    wrapped_method = google.api.core.gapic_v1.method.wrap_method(
        method, default_retry, default_timeout)

    # Overriding only the retry's deadline should also override the timeout's
    # deadline.
    result = wrapped_method(retry=default_retry.with_deadline(30))

    assert result == 42
    timeout_args = [call[1]['timeout'] for call in method.call_args_list]
    assert timeout_args == [5, 10, 20, 29]
Exemple #6
0
 def test_constructor_args(self):
     timeout_ = timeout.ExponentialTimeout(1, 2, 3, 4)
     assert timeout_._initial == 1
     assert timeout_._maximum == 2
     assert timeout_._multiplier == 3
     assert timeout_._deadline == 4
Exemple #7
0
 def test_constructor(self):
     timeout_ = timeout.ExponentialTimeout()
     assert timeout_._initial == timeout._DEFAULT_INITIAL_TIMEOUT
     assert timeout_._maximum == timeout._DEFAULT_MAXIMUM_TIMEOUT
     assert timeout_._multiplier == timeout._DEFAULT_TIMEOUT_MULTIPLIER
     assert timeout_._deadline == timeout._DEFAULT_DEADLINE
Exemple #8
0
 def test___str__(self):
     timeout_ = timeout.ExponentialTimeout(1, 2, 3, 4)
     assert str(timeout_) == (
         '<ExponentialTimeout initial=1.0, maximum=2.0, multiplier=3.0, '
         'deadline=4.0>')