예제 #1
0
    def test_retry_timeout(self, sleep, request):
        """Test HTTP request via call() with timeouts."""

        request.side_effect = [Timeout, ConnectionError, timeout, Timeout]

        with assert_raises(Timeout):
            call('http://genie-timeout', attempts=4, backoff=0)

        assert_equals(4, request.call_count)
        assert_equals(3, sleep.call_count)
예제 #2
0
    def test_404_not_none(self, sleep, request):
        """Test HTTP request via call() with 404 response (raise error)."""

        request.return_value = fake_response({}, 404)

        with assert_raises(GenieHTTPError):
            call('http://genie-404-raise', attempts=1, backoff=0)

        assert_equals(1, request.call_count)
        assert_equals(0, sleep.call_count)
예제 #3
0
    def test_503_409(self, sleep, request):
        """Test HTTP request via call() with 503 then 409 responses."""

        request.side_effect = [fake_response({}, 503), fake_response({}, 409)]

        with assert_raises(GenieHTTPError):
            call('http://genie-503-409', attempts=4, backoff=0)

        assert_equals(2, request.call_count)
        assert_equals(1, sleep.call_count)
예제 #4
0
    def test_404_not_none(self, sleep, request):
        """Test HTTP request via call() with 404 response (raise error)."""

        request.return_value = fake_response({}, 404)

        with assert_raises(GenieHTTPError):
            call('http://genie-404-raise', attempts=1, backoff=0)

        assert_equals(1, request.call_count)
        assert_equals(0, sleep.call_count)
예제 #5
0
    def test_retry_timeout_202(self, sleep, request):
        """Test HTTP request via call() with timeouts (finishing with 202)."""

        request.side_effect = [
            Timeout, ConnectionError,
            fake_response({}, 202), timeout, Timeout
        ]

        call('http://genie-timeout-202', attempts=5, backoff=0)

        assert_equals(3, request.call_count)
        assert_equals(2, sleep.call_count)
예제 #6
0
    def test_retry_timeout_404(self, sleep, request):
        """Test HTTP request via call() with timeouts (finishing with 404)."""

        request.side_effect = [
            Timeout, ConnectionError, timeout,
            fake_response({}, 404), Timeout, ConnectionError, timeout
        ]

        with assert_raises(GenieHTTPError):
            call('http://genie-timeout-404', attempts=7, backoff=0)

        assert_equals(4, request.call_count)
        assert_equals(3, sleep.call_count)
예제 #7
0
    def test_retry_timeout_202(self, sleep, request):
        """Test HTTP request via call() with timeouts (finishing with 202)."""

        request.side_effect = [
            Timeout,
            ConnectionError,
            fake_response({}, 202),
            timeout,
            Timeout
        ]

        call('http://genie-timeout-202', attempts=5, backoff=0)

        assert_equals(3, request.call_count)
        assert_equals(2, sleep.call_count)
예제 #8
0
    def test_retry_timeout(self, sleep, request):
        """Test HTTP request via call() with timeouts."""

        request.side_effect = [
            Timeout,
            ConnectionError,
            timeout,
            Timeout,
            ConnectionError,
        ]

        with assert_raises(Timeout):
            call('http://genie-timeout', attempts=4, backoff=0)

        assert_equals(4, request.call_count)
        assert_equals(3, sleep.call_count)
예제 #9
0
    def test_retry_codes_2(self, sleep, request):
        """Test HTTP request via call() with retry status codes (finishing with 202)."""

        request.side_effect = [
            fake_response({}, 500),
            fake_response({}, 503),
            fake_response({}, 202)
        ]

        call('http://genie-retry-codes-202',
             retry_status_codes=500,
             attempts=4,
             backoff=0)

        assert_equals(3, request.call_count)
        assert_equals(2, sleep.call_count)
예제 #10
0
    def test_202(self, request):
        """Test HTTP request via call() with 200 response."""

        request.return_value = fake_response({}, 202)

        resp = call('http://genie-202')

        assert_equals(202, resp.status_code)
        assert_equals(1, request.call_count)
예제 #11
0
    def test_202(self, request):
        """Test HTTP request via call() with 200 response."""

        request.return_value = fake_response({}, 202)

        resp = call('http://genie-202')

        assert_equals(202, resp.status_code)
        assert_equals(1, request.call_count)
예제 #12
0
    def test_404_none(self, sleep, request):
        """Test HTTP request via call() with 404 response (return None)."""

        request.return_value = fake_response({}, 404)

        resp = call('http://genie-404-none', none_on_404=True, attempts=1, backoff=0)

        assert_equals(None, resp)
        assert_equals(1, request.call_count)
        assert_equals(0, sleep.call_count)
예제 #13
0
    def test_retry_codes(self, sleep, request):
        """Test HTTP request via call() with retry status codes."""

        request.side_effect = [
            fake_response({}, 500),
            fake_response({}, 503),
            fake_response({}, 500),
            fake_response({}, 503),
            fake_response({}, 500)
        ]

        with assert_raises(GenieHTTPError):
            call('http://genie-retry-codes',
                 retry_status_codes=500,
                 attempts=4,
                 backoff=0)

        assert_equals(4, request.call_count)
        assert_equals(3, sleep.call_count)
예제 #14
0
    def test_404_none(self, sleep, request):
        """Test HTTP request via call() with 404 response (return None)."""

        request.return_value = fake_response({}, 404)

        resp = call('http://genie-404-none', none_on_404=True, attempts=1, backoff=0)

        assert_equals(None, resp)
        assert_equals(1, request.call_count)
        assert_equals(0, sleep.call_count)
예제 #15
0
    def test_failure_code(self, sleep, request):
        """Test HTTP request via call() with a failure status code."""

        request.side_effect = [
            fake_response({}, 500),
            fake_response({}, 503),
            fake_response({}, 500),
            fake_response({}, 412),
            fake_response({}, 503),
            fake_response({}, 500),
            fake_response({}, 412),
            fake_response({}, 503),
            fake_response({}, 500)
        ]

        with assert_raises(GenieHTTPError):
            call('http://genie-failure-code', failure_codes=412, attempts=10, backoff=0)

        assert_equals(4, request.call_count)
        assert_equals(3, sleep.call_count)
예제 #16
0
    def test_failure_code(self, sleep, request):
        """Test HTTP request via call() with a failure status code."""

        request.side_effect = [
            fake_response({}, 500),
            fake_response({}, 503),
            fake_response({}, 500),
            fake_response({}, 412),
            fake_response({}, 503),
            fake_response({}, 500),
            fake_response({}, 412),
            fake_response({}, 503),
            fake_response({}, 500)
        ]

        with assert_raises(GenieHTTPError):
            call('http://genie-failure-code', failure_codes=412, attempts=10, backoff=0)

        assert_equals(4, request.call_count)
        assert_equals(3, sleep.call_count)
예제 #17
0
    def test_various_status_code_retries(self, sleep, request):
        """Test HTTP request via call() with various non-200 status code responses."""

        request.side_effect = [
            fake_response({}, 403),
            fake_response({}, 403),
            fake_response({}, 404),
            fake_response({}, 404),
            fake_response({}, 409),
            fake_response({}, 409),
            fake_response({}, 412),
            fake_response({}, 503),
            fake_response({}, 503),
            fake_response({}, 504),
        ]

        with assert_raises(GenieHTTPError):
            call('http://genie-non-200', attempts=10, backoff=0)

        assert_equals(10, request.call_count)
        assert_equals(9, sleep.call_count)
예제 #18
0
    def test_retry_timeout_404(self, sleep, request):
        """Test HTTP request via call() with timeouts with failure code."""

        request.side_effect = [
            Timeout,
            ConnectionError,
            timeout,
            fake_response({}, 404),
            Timeout,
            ConnectionError,
            timeout,
            Timeout,
            ConnectionError,
            timeout
        ]

        with assert_raises(GenieHTTPError):
            call('http://genie-timeout-404', failure_codes=404, attempts=7, backoff=0)

        assert_equals(4, request.call_count)
        assert_equals(3, sleep.call_count)
예제 #19
0
    def test_various_status_code_retries(self, sleep, request):
        """Test HTTP request via call() with various non-200 status code responses."""

        request.side_effect = [
            fake_response({}, 403),
            fake_response({}, 403),
            fake_response({}, 404),
            fake_response({}, 404),
            fake_response({}, 409),
            fake_response({}, 409),
            fake_response({}, 412),
            fake_response({}, 503),
            fake_response({}, 503),
            fake_response({}, 504),
        ]

        with assert_raises(GenieHTTPError):
            call('http://genie-non-200', attempts=10, backoff=0)

        assert_equals(10, request.call_count)
        assert_equals(9, sleep.call_count)
예제 #20
0
    def test_503_202(self, sleep, request):
        """Test HTTP request via call() with 503 then 202 responses."""

        request.side_effect = [
            fake_response({}, 503),
            fake_response({}, 503),
            fake_response({}, 202)
        ]

        resp = call('http://genie-503-202', attempts=4, backoff=0)

        assert_equals(202, resp.status_code)
        assert_equals(3, request.call_count)
        assert_equals(2, sleep.call_count)
예제 #21
0
    def test_retry_timeout_404_return_none(self, sleep, request):
        """Test HTTP request via call() with timeouts (finishing with 404 but return None)."""

        request.side_effect = [
            Timeout, ConnectionError, timeout,
            fake_response({}, 404), Timeout, ConnectionError, timeout
        ]

        resp = call('http://genie-timeout-404',
                    attempts=7,
                    backoff=0,
                    none_on_404=True)

        assert_equals(4, request.call_count)
        assert_equals(3, sleep.call_count)
        assert_equals(None, resp)
예제 #22
0
    def test_retry_timeout_404_return_none(self, sleep, request):
        """Test HTTP request via call() with timeouts (finishing with 404 but return None)."""

        request.side_effect = [
            Timeout,
            ConnectionError,
            timeout,
            fake_response({}, 404),
            Timeout,
            ConnectionError,
            timeout
        ]

        resp = call('http://genie-timeout-404',
                    attempts=7,
                    backoff=0,
                    failure_codes=404,
                    none_on_404=True)

        assert_equals(4, request.call_count)
        assert_equals(3, sleep.call_count)
        assert_equals(None, resp)
예제 #23
0
    def test_503_200(self, sleep, request):
        """Test HTTP request via call() with non-200 responses then 200 response."""

        request.side_effect = [
            fake_response({}, 403),
            fake_response({}, 404),
            fake_response({}, 409),
            fake_response({}, 412),
            fake_response({}, 503),
            fake_response({}, 504),
            fake_response({}, 200),
            fake_response({}, 403),
            fake_response({}, 404),
            fake_response({}, 409),
            fake_response({}, 412),
            fake_response({}, 503),
            fake_response({}, 504)
        ]

        resp = call('http://genie-non-200-200', attempts=10, backoff=0)

        assert_equals(200, resp.status_code)
        assert_equals(7, request.call_count)
        assert_equals(6, sleep.call_count)
예제 #24
0
    def test_503_200(self, sleep, request):
        """Test HTTP request via call() with non-200 responses then 200 response."""

        request.side_effect = [
            fake_response({}, 403),
            fake_response({}, 404),
            fake_response({}, 409),
            fake_response({}, 412),
            fake_response({}, 503),
            fake_response({}, 504),
            fake_response({}, 200),
            fake_response({}, 403),
            fake_response({}, 404),
            fake_response({}, 409),
            fake_response({}, 412),
            fake_response({}, 503),
            fake_response({}, 504)
        ]

        resp = call('http://genie-non-200-200', attempts=10, backoff=0)

        assert_equals(200, resp.status_code)
        assert_equals(7, request.call_count)
        assert_equals(6, sleep.call_count)