def test_retry_on_timeout_retry(self, Class, retries): 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
def test_connect_without_retry_on_os_error(self): """Test that the _connect function is not being retried in case of a OSError""" with patch.object(Connection, "_connect") as _connect: _connect.side_effect = OSError("") conn = Connection(retry_on_timeout=True, retry=Retry(NoBackoff(), 2)) with pytest.raises(ConnectionError): conn.connect() assert _connect.call_count == 1 self.clear(conn)
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 test_client_retry_on_timeout(self, request): with patch.object(Redis, "parse_response") as parse_response: parse_response.side_effect = TimeoutError() retries = 3 r = _get_client(Redis, request, retry_on_timeout=True, retry=Retry(NoBackoff(), retries)) with pytest.raises(TimeoutError): try: r.get("foo") finally: assert parse_response.call_count == retries + 1
def test_client_retry_on_error_different_error_raised(self, request): with patch.object(Redis, "parse_response") as parse_response: parse_response.side_effect = TimeoutError() retries = 3 r = _get_client( Redis, request, retry_on_error=[ReadOnlyError], retry=Retry(NoBackoff(), retries), ) with pytest.raises(TimeoutError): try: r.get("foo") finally: assert parse_response.call_count == 1
def test_retry_connect_on_timeout_error(self): """Test that the _connect function is retried in case of a timeout""" conn = Connection(retry_on_timeout=True, retry=Retry(NoBackoff(), 3)) origin_connect = conn._connect conn._connect = mock.Mock() def mock_connect(): # connect only on the last retry if conn._connect.call_count <= 2: raise socket.timeout else: return origin_connect() conn._connect.side_effect = mock_connect conn.connect() assert conn._connect.call_count == 3 self.clear(conn)
def _gen_cluster_mock_resp(r, response): connection = Mock() connection.retry = Retry(NoBackoff(), 0) connection.read_response.return_value = response r.connection = connection return r
def test_retry_on_error_retry(self, Class, retries): c = Class(retry_on_error=[ReadOnlyError], retry=Retry(NoBackoff(), retries)) assert c.retry_on_error == [ReadOnlyError] assert isinstance(c.retry, Retry) assert c.retry._retries == retries
def __init__(self, client): self.client = client self._sock = self._socket() self.pid = 1234 self.retry = Retry(NoBackoff(), 0)