Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 def testRetriableCleanupIsCalled(self):
     cleanup = mock.Mock()
     func = retriable(cleanup=cleanup, sleeptime=0, jitter=0)(
         _succeedOnSecondAttempt
     )
     func()
     self.assertEqual(cleanup.call_count, 1)
Ejemplo n.º 3
0
 def testRetriableReturns(self):
     func = retriable(sleeptime=0, jitter=0)(_alwaysPass)
     ret = func()
     self.assertEqual(ret, True)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 def testRetriableWithSleep(self):
     func = retriable(attempts=2, sleeptime=1)(_succeedOnSecondAttempt)
     func()
Ejemplo n.º 6
0
 def testRetriableSelectiveExceptionFail(self):
     func = retriable(
         attempts=2, sleeptime=0, jitter=0, retry_exceptions=(OtherError,)
     )(_raiseCustomException)
     self.assertRaises(NewError, func)
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 def testRetriableFailWithoutCatching(self):
     func = retriable(sleeptime=0)(_alwaysFail)
     self.assertRaises(Exception, func, retry_exceptions=())
Ejemplo n.º 9
0
 def testRetriableSelectiveExceptionSucceed(self):
     func = retriable(attempts=2,
                      sleeptime=0,
                      jitter=0,
                      retry_exceptions=(NewError, ))(_raiseCustomException)
     func()
Ejemplo n.º 10
0
 def testRetriableFailEnsureRaisesLastException(self):
     func = retriable(sleeptime=0)(_alwaysFail)
     self.assertRaises(Exception, func)
Ejemplo n.º 11
0
 def testRetriableFailWithoutCatching(self):
     func = retriable(sleeptime=0)(_alwaysFail)
     self.assertRaises(Exception, func, retry_exceptions=())
Ejemplo n.º 12
0
 def testRetriableSucceed(self):
     func = retriable(attempts=2, sleeptime=0,
                      jitter=0)(_succeedOnSecondAttempt)
     func()
Ejemplo n.º 13
0
 def testRetriableCleanupIsCalled(self):
     cleanup = mock.Mock()
     func = retriable(cleanup=cleanup, sleeptime=0,
                      jitter=0)(_succeedOnSecondAttempt)
     func()
     self.assertEqual(cleanup.call_count, 1)
Ejemplo n.º 14
0
 def testRetriableReturns(self):
     func = retriable(sleeptime=0, jitter=0)(_alwaysPass)
     ret = func()
     self.assertEqual(ret, True)
Ejemplo n.º 15
0
 def testRetriableSelectiveExceptionFail(self):
     func = retriable(
         attempts=2, sleeptime=0, jitter=0,
         retry_exceptions=(OtherError, ))(_raiseCustomException)
     self.assertRaises(NewError, func)
Ejemplo n.º 16
0
 def testRetriableSucceed(self):
     func = retriable(attempts=2, sleeptime=0, jitter=0)(_succeedOnSecondAttempt)
     func()
Ejemplo n.º 17
0
 def testRetriableSelectiveExceptionSucceed(self):
     func = retriable(
         attempts=2, sleeptime=0, jitter=0, retry_exceptions=(NewError,)
     )(_raiseCustomException)
     func()
Ejemplo n.º 18
0
 def testRetriableFailEnsureRaisesLastException(self):
     func = retriable(sleeptime=0)(_alwaysFail)
     self.assertRaises(Exception, func)
Ejemplo n.º 19
0
 def testRetriableWithSleep(self):
     func = retriable(attempts=2, sleeptime=1)(_succeedOnSecondAttempt)
     func()