Beispiel #1
0
    def test_retry_returns_on_first_success(self):
        fail = failed_response()
        success = ok_response()
        sender = mock_sender(fail, fail, success, fail, success)

        s = RetryingSender(retries=5, sender=sender)
        with patch(module + '.time', MagicMock()):
            s.send(mock_request())
        assert sender.send.call_count == 3
Beispiel #2
0
    def test_rate_limited_request_retried_after_set_seconds(self):
        time = MagicMock()
        fail = rate_limit_response()
        success = ok_response()
        sender = mock_sender(fail, success)

        s = RetryingSender(sender=sender)
        with patch(module + '.time', time):
            s.send(mock_request())
            time.sleep.assert_called_once_with(1 + 1)
Beispiel #3
0
    def test_default_retry_after_is_one(self):
        time = MagicMock()
        fail = rate_limit_response()
        del fail.headers['Retry-After']
        success = ok_response()
        sender = mock_sender(fail, success)

        s = RetryingSender(sender=sender)
        with patch(module + '.time', time):
            s.send(mock_request())
            time.sleep.assert_called_once_with(1 + 1)
Beispiel #4
0
    def test_rate_limited_retry_doesnt_decrease_retry_count(self):
        fail = failed_response()
        rate = rate_limit_response()
        success = ok_response()
        sender = mock_sender(fail, rate, fail, success)

        s = RetryingSender(retries=2, sender=sender)
        with patch(module + '.time', MagicMock()):
            s.send(mock_request())

        assert sender.send.call_count == 4
Beispiel #5
0
 def test_failing_request_but_no_retries_returns_failed(self):
     fail = failed_response()
     success = ok_response()
     sender = mock_sender(fail, success)
     s = RetryingSender(sender=sender)
     r = s.send(mock_request())
     assert r is fail