def testMul2(self): bi = simpleBackoffIterator(now=False, initDelay=1.0, incFunc=partial(mul, 2.0), maxDelay=10.0, maxResults=10) self.assertEqual(1.0, bi.next()) self.assertEqual(2.0, bi.next()) self.assertEqual(4.0, bi.next())
def testAdd3(self): 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())
def testConstant(self): 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())
def testMaxResults(self): maxResults = 12 bi = simpleBackoffIterator(now=False, maxResults=maxResults) for _ in range(maxResults): bi.next() self.assertRaises(StopIteration, bi.next)
def testDefaultSettingsNoNegativeDelays(self): bi = simpleBackoffIterator() for delay in bi: self.assertTrue(delay >= 0.0)
def testDefaultSettingsEventuallyHalt(self): bi = simpleBackoffIterator() for delay in bi: pass
def testInitDelay(self): initDelay = 7 bi = simpleBackoffIterator(now=False, initDelay=initDelay, maxDelay=initDelay + 1) delay = bi.next() self.assertEqual(initDelay, delay)
def testNotNow(self): bi = simpleBackoffIterator(now=False, initDelay=3.0) delay = bi.next() self.assertNotEqual(0.0, delay)
def testNow(self): bi = simpleBackoffIterator(now=True, initDelay=9) delay = bi.next() self.assertEqual(0.0, delay)