Skip to content

Commit

Permalink
Add handling of timeout setting in request_options
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaensch committed Jan 22, 2018
1 parent 62b5aff commit a7fc5e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions bravado_asyncio/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,22 @@ def request(self, request_params, operation=None, response_callbacks=None,
data.add_field(name, stream_obj, filename=file_tuple[0])

params = self.prepare_params(request_params.get('params'))

connect_timeout = request_params.get('connect_timeout')
if connect_timeout:
log.warning(
'bravado-asyncio does not support setting a connect_timeout '
'(you passed a value of {})'.format(connect_timeout),
)
timeout = request_params.get('timeout')

coroutine = client_session.request(
method=request_params.get('method') or 'GET',
url=request_params.get('url'),
params=params,
data=data,
headers=request_params.get('headers'),
timeout=timeout,
)

future = asyncio.run_coroutine_threadsafe(coroutine, get_loop())
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,18 @@ def test_server_500(swagger_client):
swagger_client.pet.deletePet(petId=42).result(timeout=1)


def test_timeout(swagger_client):
def test_timeout_on_future(swagger_client):
with pytest.raises(BravadoTimeoutError):
bravado_future = swagger_client.store.getInventory()
bravado_future.result(timeout=0.1)


def test_timeout_request_options(swagger_client):
with pytest.raises(BravadoTimeoutError):
bravado_future = swagger_client.store.getInventory(_request_options={'timeout': 0.1})
bravado_future.result(timeout=None)


def test_client_from_asyncio(integration_server):
"""Let's make sure that the event loop for our HTTP client that runs in a different thread
behaves properly with the 'standard' asyncio loop that people would normally use when doing
Expand Down

0 comments on commit a7fc5e4

Please sign in to comment.