Exemplo n.º 1
0
    def test_remaining(self):
        backoff = Backoff()
        for attempt in range(backoff.max_attempts):
            now = datetime.utcnow()

            if attempt == 0:
                assert backoff.remaining(attempt, now) == timedelta()
                continue

            expect_delta = timedelta(seconds=2**attempt)
            assert backoff.remaining(attempt, now) > timedelta()
            assert backoff.remaining(attempt, now) < expect_delta
            assert backoff.remaining(attempt,
                                     now - expect_delta) == timedelta()
            assert backoff.remaining(attempt,
                                     now + expect_delta) > expect_delta
Exemplo n.º 2
0
 def test_all_attempts_edge(self):
     backoff = Backoff()
     assert backoff.max_attempts == Backoff.max_attempts
     assert len(backoff.deltas) == 16
     for edge in [-1, 0, 15, 16, 17]:
         assert backoff.delta(edge) >= backoff.zero
         assert backoff.remaining(edge, datetime.utcnow()) >= backoff.zero
         if edge > 0:
             assert backoff.expires(edge,
                                    datetime.utcnow()) >= datetime.utcnow()
             assert backoff.expired(edge, datetime.utcnow()) == False
         else:
             assert backoff.expires(edge,
                                    datetime.utcnow()) <= datetime.utcnow()
             assert backoff.expired(edge, datetime.utcnow())