def test_expires(self): tracker = Tracker() for attempt in range(tracker.backoff.max_attempts): now = datetime.utcnow() if attempt == 0: assert tracker.expires() < datetime.utcnow() continue tracker.attempt() expect_delta = timedelta(seconds=2**attempt) assert tracker.expires() > datetime.utcnow() tracker.last_attempt = now - expect_delta assert tracker.expires() < datetime.utcnow() tracker.last_attempt = now - (expect_delta * 2) assert tracker.expires() < datetime.utcnow() tracker.last_attempt = now + expect_delta assert tracker.expires() > datetime.utcnow() tracker.last_attempt = now + (expect_delta * 2) assert tracker.expires() > datetime.utcnow()
def test_expires_overflow(self): tracker = Tracker() tracker.attempts = 15 tracker.last_attempt = datetime.max assert tracker.expires() == datetime.max