def test_retry_with_retry_on_timeout(self, Class, retries: int): retry_on_timeout = retries > 0 c = Class(retry_on_timeout=retry_on_timeout, retry=Retry(NoBackoff(), retries)) assert c.retry_on_timeout == retry_on_timeout assert isinstance(c.retry, Retry) assert c.retry._retries == retries
async def test_infinite_retry(self): backoff = BackoffMock() # specify infinite retries, but give up after 5 retry = Retry(backoff, -1) with pytest.raises(ConnectionError): await retry.call_with_retry(self._do, self._fail_inf) assert self.actual_attempts == 5 assert self.actual_failures == 5
async def test_retry(self, retries: int): backoff = BackoffMock() retry = Retry(backoff, retries) with pytest.raises(ConnectionError): await retry.call_with_retry(self._do, self._fail) assert self.actual_attempts == 1 + retries assert self.actual_failures == 1 + retries assert backoff.reset_calls == 1 assert backoff.calls == retries
def test_retry_with_retry_on_error(self, Class, retries: int): class CustomError(Exception): pass retry_on_error = [ConnectionError, TimeoutError, CustomError] c = Class(retry_on_error=retry_on_error, retry=Retry(NoBackoff(), retries)) assert c.retry_on_error == retry_on_error assert isinstance(c.retry, Retry) assert c.retry._retries == retries assert set(c.retry._supported_errors) == set(retry_on_error)
def _gen_cluster_mock_resp(r, response): connection = mock.AsyncMock() connection.retry = Retry(NoBackoff(), 0) connection.read_response.return_value = response r.connection = connection return r