def test_backoff_reset_after_redirect(self): retry = Retry(total=100, redirect=5, backoff_factor=0.2) retry = retry.increment(method='GET') retry = retry.increment(method='GET') assert retry.get_backoff_time() == 0.4 redirect_response = HTTPResponse(status=302, headers={'location': 'test'}) retry = retry.increment(method='GET', response=redirect_response) assert retry.get_backoff_time() == 0 retry = retry.increment(method='GET') retry = retry.increment(method='GET') assert retry.get_backoff_time() == 0.4
def test_backoff(self): """ Backoff is computed correctly """ max_backoff = Retry.BACKOFF_MAX retry = Retry(total=100, backoff_factor=0.2) assert retry.get_backoff_time() == 0 # First request retry = retry.increment(method='GET') assert retry.get_backoff_time() == 0 # First retry retry = retry.increment(method='GET') assert retry.backoff_factor == 0.2 assert retry.total == 98 assert retry.get_backoff_time() == 0.4 # Start backoff retry = retry.increment(method='GET') assert retry.get_backoff_time() == 0.8 retry = retry.increment(method='GET') assert retry.get_backoff_time() == 1.6 for _ in xrange(10): retry = retry.increment(method='GET') assert retry.get_backoff_time() == max_backoff
def test_zero_backoff(self): retry = Retry() assert retry.get_backoff_time() == 0 retry = retry.increment(method='GET') retry = retry.increment(method='GET') assert retry.get_backoff_time() == 0