Skip to content

Commit

Permalink
We should use ReadTimeout for the requests client
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaensch committed Dec 7, 2017
1 parent c524bce commit 95f28d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bravado/requests_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import requests
import requests.auth
import requests.exceptions
import six
from bravado_core.response import IncomingResponse
from six import iteritems
Expand Down Expand Up @@ -215,7 +216,7 @@ class RequestsFutureAdapter(FutureAdapter):
HTTP calls with the Requests library in a future-y sort of way.
"""

timeout_errors = [requests.Timeout]
timeout_errors = [requests.exceptions.ReadTimeout]

def __init__(self, session, request, misc_options):
"""Kicks API call for Requests client
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/requests_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import mock
import pytest
import requests
import requests.exceptions
import umsgpack
from bravado_core.content_type import APP_MSGPACK

Expand Down Expand Up @@ -147,6 +148,17 @@ def test_timeout_errors_are_catchable_with_original_exception_types(self, thread
'params': {},
}).result(timeout=0.01)

def test_timeout_errors_are_catchable_as_requests_timeout(self, threaded_http_server):
if not self.http_client_type == RequestsClient:
pytest.skip('{} is not using RequestsClient'.format(self.http_future_adapter_type))

with pytest.raises(requests.exceptions.Timeout):
self.http_client.request({
'method': 'GET',
'url': '{server_address}/sleep?sec=0.1'.format(server_address=threaded_http_server),
'params': {},
}).result(timeout=0.01)


class FakeRequestsFutureAdapter(RequestsFutureAdapter):
timeout_errors = []
Expand Down

0 comments on commit 95f28d3

Please sign in to comment.