Esempio n. 1
0
    def test_maxRetries(self):
        """
        The iterator gets exhausted if retries are capped.
        """
        it = retrying.simpleBackoffIterator(maxRetries=3)

        it.next(), it.next(), it.next()
        self.assertRaises(StopIteration, it.next)
Esempio n. 2
0
    def test_noMaxRetries(self):
        """
        The iterator does not get exhausted if retries are not capped.
        """
        it = retrying.simpleBackoffIterator(maxRetries=0, maxDelay=1)

        alot = [it.next() for _ in range(1000)]
        self.assertEquals(alot[-1], 1)
Esempio n. 3
0
    def test_maxDelay(self):
        """
        The delay is capped at some point.
        """
        it = retrying.simpleBackoffIterator(maxDelay=2.0)

        res = [it.next() for _ in range(5)]
        self.assertEquals(res[-1], 2.0)
Esempio n. 4
0
    def test_noMaxRetries(self):
        """
        The iterator does not get exhausted if retries are not capped.
        """
        it = retrying.simpleBackoffIterator(maxRetries=0, maxDelay=1)

        alot = [next(it) for _ in range(1000)]
        self.assertEquals(alot[-1], 1)
Esempio n. 5
0
    def test_maxRetries(self):
        """
        The iterator gets exhausted if retries are capped.
        """
        it = retrying.simpleBackoffIterator(maxRetries=3)

        next(it), next(it), next(it)
        self.assertRaises(StopIteration, lambda: next(it))
Esempio n. 6
0
    def test_maxDelay(self):
        """
        The delay is capped at some point.
        """
        it = retrying.simpleBackoffIterator(maxDelay=2.0)

        res = [next(it) for _ in range(5)]
        self.assertEquals(res[-1], 2.0)
Esempio n. 7
0
    def test_noMaxDelay(self):
        """
        Without maximum delay, the consecutive delays grow unboundedly.
        """
        it = retrying.simpleBackoffIterator(maxRetries=0, maxDelay=0)

        # putting range(1000) here makes Python return a NaN, so be moderate
        alot = [it.next() for _ in range(100)]
        self.assertTrue(alot[-2] < alot[-1])
Esempio n. 8
0
    def setUp(self):
        self.calls = 0
        self.raiseError = None

        self.clock = task.Clock()
        self.call = retrying.RetryingCall(self.func)
        self.call.reactor = self.clock
        self.sillyIterator = retrying.simpleBackoffIterator(
            initialDelay=1, factor=1, jitter=0, maxDelay=0, maxRetries=0)
Esempio n. 9
0
    def test_noMaxDelay(self):
        """
        Without maximum delay, the consecutive delays grow unboundedly.
        """
        it = retrying.simpleBackoffIterator(maxRetries=0, maxDelay=0)

        # putting range(1000) here makes Python return a NaN, so be moderate
        alot = [next(it) for _ in range(100)]
        self.assertTrue(alot[-2] < alot[-1])
Esempio n. 10
0
def defaultReconnectionIterator():
    """
    A function returning sane defaults for a reconnection iterator, for use
    with :class:`.DeadConnectionDetector`.

    The defaults have maximum reconnection delay capped at 10 seconds and no
    limit on the number of retries.
    """
    return retrying.simpleBackoffIterator(
        initialDelay=1.0, maxDelay=10.0, factor=1.7, maxRetries=0, now=True)
Esempio n. 11
0
    def test_simple(self):
        """
        Consecutive delays are increasing.
        """
        it = retrying.simpleBackoffIterator()

        # by default "now" is set
        self.assertEquals(it.next(), 0)

        r1, r2, r3 = it.next(), it.next(), it.next()
        self.assertTrue(r1 < r2 < r3)
Esempio n. 12
0
    def test_simple(self):
        """
        Consecutive delays are increasing.
        """
        it = retrying.simpleBackoffIterator()

        # by default "now" is set
        self.assertEquals(next(it), 0)

        r1, r2, r3 = next(it), next(it), next(it)
        self.assertTrue(r1 < r2 < r3)
Esempio n. 13
0
    def test_maxRetries(self):
        """
        The iterator gets exhausted if retries are capped.
        """
        it = retrying.simpleBackoffIterator(maxRetries=3)

        next(it), next(it), next(it)
        try :
            next(it)
        except StopIteration :
            pass
        else :
            self.assertFalse(True, "Stop Iteration not raised")
Esempio n. 14
0
    def test_precise(self):
        """
        Knowing starting values and disabling jitter, it is possible to predict
        consecutive values.
        """
        it = retrying.simpleBackoffIterator(initialDelay=10, maxDelay=90,
                                            factor=2, jitter=0)

        self.assertEquals(next(it), 0)
        self.assertEquals(next(it), 20)
        self.assertEquals(next(it), 40)
        self.assertEquals(next(it), 80)
        self.assertEquals(next(it), 90)
        self.assertEquals(next(it), 90)
Esempio n. 15
0
 def test_notNow(self):
     """
     If now is not set, the first delay is not zero.
     """
     it = retrying.simpleBackoffIterator(now=False)
     self.assertNotEquals(it.next(), 0)
Esempio n. 16
0
 def test_notNow(self):
     """
     If now is not set, the first delay is not zero.
     """
     it = retrying.simpleBackoffIterator(now=False)
     self.assertNotEquals(next(it), 0)