def testRetriableArgsPassed(self): args = (1, "two", 3) kwargs = dict(foo="a", bar=7) func = retriable(sleeptime=0, jitter=0)(_mirrorArgs) ret = func(*args, **kwargs) self.assertEqual(ret[0], args) self.assertEqual(ret[1], kwargs)
def testRetriableCleanupIsCalled(self): cleanup = mock.Mock() func = retriable(cleanup=cleanup, sleeptime=0, jitter=0)( _succeedOnSecondAttempt ) func() self.assertEqual(cleanup.call_count, 1)
def testRetriableReturns(self): func = retriable(sleeptime=0, jitter=0)(_alwaysPass) ret = func() self.assertEqual(ret, True)
def testRetriableOnlyRunOnce(self): global ATTEMPT_N func = retriable(attempts=3, sleeptime=0, jitter=0)(_alwaysPass) func() # ATTEMPT_N gets increased regardless of pass/fail self.assertEqual(2, ATTEMPT_N)
def testRetriableWithSleep(self): func = retriable(attempts=2, sleeptime=1)(_succeedOnSecondAttempt) func()
def testRetriableSelectiveExceptionFail(self): func = retriable( attempts=2, sleeptime=0, jitter=0, retry_exceptions=(OtherError,) )(_raiseCustomException) self.assertRaises(NewError, func)
def testRetriableFailWithoutCatching(self): func = retriable(sleeptime=0)(_alwaysFail) self.assertRaises(Exception, func, retry_exceptions=())
def testRetriableSelectiveExceptionSucceed(self): func = retriable(attempts=2, sleeptime=0, jitter=0, retry_exceptions=(NewError, ))(_raiseCustomException) func()
def testRetriableFailEnsureRaisesLastException(self): func = retriable(sleeptime=0)(_alwaysFail) self.assertRaises(Exception, func)
def testRetriableSucceed(self): func = retriable(attempts=2, sleeptime=0, jitter=0)(_succeedOnSecondAttempt) func()
def testRetriableCleanupIsCalled(self): cleanup = mock.Mock() func = retriable(cleanup=cleanup, sleeptime=0, jitter=0)(_succeedOnSecondAttempt) func() self.assertEqual(cleanup.call_count, 1)
def testRetriableSelectiveExceptionFail(self): func = retriable( attempts=2, sleeptime=0, jitter=0, retry_exceptions=(OtherError, ))(_raiseCustomException) self.assertRaises(NewError, func)
def testRetriableSelectiveExceptionSucceed(self): func = retriable( attempts=2, sleeptime=0, jitter=0, retry_exceptions=(NewError,) )(_raiseCustomException) func()