Subclasses should define:
ServiceError:
- The error class to trap (CloudServiceError or similar).
+ An exceptions class with meaningful status codes that can be
+ filtered using _react_to_error. Other exceptions will cause
+ unconditional retries.
and can override:
_react_to_error(self, response_code):
return d
def _handle_error(self, f, trynum, first_err_and_tb, description, operation, *args, **kwargs):
- f.trap(self.ServiceError, TimeoutError)
-
# Don't use f.getTracebackObject() since a fake traceback will not do for the 3-arg form of 'raise'.
# tb can be None (which is acceptable for 3-arg raise) if we don't have a traceback.
tb = getattr(f, 'tb', None)
second.callback(done)
self.assertEqual(result, [done])
- def test_retry_timeout(self):
+ def test_retry_random_exception(self):
"""
- If an HTTP connection fails with a timeout, retry.
+ If a HTTP request fails with any exception at all, retry.
"""
+ class NewException(Exception):
+ pass
first, second = defer.Deferred(), defer.Deferred()
self.container._http_request = mock.create_autospec(
self.container._http_request, side_effect=[first, second])
body=None, need_response_body=True)
# First response fails:
- from twisted.internet.error import TimeoutError
- first.errback(TimeoutError())
+ first.errback(NewException())
self.assertFalse(result, result)
self.assertEqual(self.container._http_request.call_count, 1)
self.reactor.advance(0.1)