Exemple #1
0
 def testMaxResults(self):
     """Ensure the maxResults argument is respected."""
     maxResults = 12
     bi = simpleBackoffIterator(now=False, maxResults=maxResults)
     for _ in range(maxResults):
         bi.next()
     self.assertRaises(StopIteration, bi.next)
Exemple #2
0
 def testInitDelay(self):
     """If an initial delay is passed, it must be the first value
     returned by the iterator."""
     initDelay = 7
     bi = simpleBackoffIterator(now=False, initDelay=initDelay)
     delay = bi.next()
     self.assertEqual(initDelay, delay)
Exemple #3
0
 def testNowDefault(self):
     """When now is not specified, the first delay the iterator returns
     must be zero (in other words we're testing that by default the
     function will be called immediately)."""
     bi = simpleBackoffIterator()
     delay = bi.next()
     self.assertEqual(0.0, delay)
Exemple #4
0
 def testAdd3(self):
     """Make a back-off iterator whose increment function adds 3 to the
     previous delay and check its results."""
     bi = simpleBackoffIterator(now=False,
                                initDelay=2.0,
                                incFunc=partial(add, 3.0),
                                maxDelay=10.0,
                                maxResults=10)
     self.assertEqual(2.0, bi.next())
     self.assertEqual(5.0, bi.next())
     self.assertEqual(8.0, bi.next())
Exemple #5
0
 def testMul3(self):
     """Make a back-off iterator whose increment function multiplies the
     previous delay by 3 and check its results."""
     bi = simpleBackoffIterator(now=False,
                                initDelay=1.0,
                                incFunc=partial(mul, 3.0),
                                maxDelay=10.0,
                                maxResults=10)
     self.assertEqual(1.0, bi.next())
     self.assertEqual(3.0, bi.next())
     self.assertEqual(9.0, bi.next())
Exemple #6
0
 def testConstant(self):
     """Make a back-off iterator that yields a constant for a certain
     number of times, and check its results."""
     n = 10
     constant = 5.0
     initDelay = 3.0
     bi = simpleBackoffIterator(now=False,
                                initDelay=initDelay,
                                incFunc=lambda _: constant,
                                maxDelay=10.0,
                                maxResults=n + 1)
     self.assertEqual(initDelay, bi.next())
     for _ in range(n):
         self.assertEqual(constant, bi.next())
Exemple #7
0
 def testMaxDelay(self):
     """Make a back-off iterator whose increment function multiplies the
     previous delay by 3 and check that it returns the passed maxDelay
     value once the delay would be too large."""
     bi = simpleBackoffIterator(now=False,
                                initDelay=1.0,
                                incFunc=partial(mul, 3.0),
                                maxDelay=10.0,
                                maxResults=10)
     self.assertEqual(1.0, bi.next())
     self.assertEqual(3.0, bi.next())
     self.assertEqual(9.0, bi.next())
     self.assertEqual(10.0, bi.next())
     self.assertEqual(10.0, bi.next())
Exemple #8
0
 def testDefaultSettingsNoNegativeDelays(self):
     """Ensure no negative values are yielded by the iterator."""
     bi = simpleBackoffIterator()
     for delay in bi:
         self.assertTrue(delay >= 0.0)
Exemple #9
0
 def exhaust():
     """Set up a default iterator and keep call its next method
     forever. If it doesn't raise this test will never finish."""
     bi = simpleBackoffIterator()
     while True:
         bi.next()
Exemple #10
0
 def testNotNow(self):
     """When now=False is passed to the back-off iterator, the first
     delay it returns must not be zero."""
     bi = simpleBackoffIterator(now=False)
     delay = bi.next()
     self.assertNotEqual(0.0, delay)
Exemple #11
0
 def testNow(self):
     """When now=True is passed to the back-off iterator, the first
     delay it returns must be zero."""
     bi = simpleBackoffIterator(now=True)
     delay = six.next(bi)
     self.assertEqual(0.0, delay)