def test_do_not_retry_for_exception_success(self): # Test that we retry for exceptions not specified. client = self.make_client( [MemcacheClientError("Whoops."), b"VALUE key 0 5\r\nvalue\r\nEND\r\n"], attempts=2, do_not_retry_for=tuple([MemcacheUnknownError]), ) result = client.get("key") assert result == b"value"
def test_retry_for_exception_success(self): # Test that we retry for the exception specified. client = self.make_client([ MemcacheClientError("Whoops."), b'VALUE key 0 5\r\nvalue\r\nEND\r\n' ], attempts=2, retry_for=tuple([MemcacheClientError])) result = client.get("key") assert result == b'value'
def test_do_not_retry_for_exception_fail(self): # Test that we do not retry for the exception specified. client = self.make_client( [MemcacheClientError("Whoops."), b"VALUE key 0 5\r\nvalue\r\nEND\r\n"], attempts=2, do_not_retry_for=tuple([MemcacheClientError]), ) with pytest.raises(MemcacheClientError): client.get("key")
def _raise_errors(self, line, name): if line.startswith(b'ERROR'): raise MemcacheUnknownCommandError(name) if line.startswith(b'CLIENT_ERROR'): error = line[line.find(b' ') + 1:] raise MemcacheClientError(error) if line.startswith(b'SERVER_ERROR'): error = line[line.find(b' ') + 1:] raise MemcacheServerError(error)
def test_both_exception_filters(self): # Test interacction between both exception filters. client = self.make_client([ MemcacheClientError("Whoops."), b'VALUE key 0 5\r\nvalue\r\nEND\r\n', MemcacheUnknownError("Whoops."), b'VALUE key 0 5\r\nvalue\r\nEND\r\n', ], attempts=2, retry_for=tuple([MemcacheClientError]), do_not_retry_for=tuple( [MemcacheUnknownError])) # Check that we succeed where allowed. result = client.get("key") assert result == b'value' # Check that no retries are attempted for the banned exception. with pytest.raises(MemcacheUnknownError): client.get("key")
def cas(self, key, value, cas, expire=0, noreply=False, flags=None): raise MemcacheClientError("CAS is not enabled for this instance")