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