|
14 | 14 | from azure.core.rest._http_response_impl_async import AsyncHttpResponseImpl as RestAsyncHttpResponse
|
15 | 15 | from azure.core.pipeline.policies import HeadersPolicy
|
16 | 16 | from azure.core.pipeline import AsyncPipeline
|
17 |
| -from azure.core.exceptions import HttpResponseError, ServiceResponseError |
| 17 | +from azure.core.exceptions import ( |
| 18 | + HttpResponseError, |
| 19 | + ServiceResponseError, |
| 20 | + ServiceRequestError, |
| 21 | + ServiceRequestTimeoutError, |
| 22 | + ServiceResponseTimeoutError, |
| 23 | +) |
18 | 24 | from utils import HTTP_REQUESTS, request_and_responses_product
|
19 | 25 | import pytest
|
20 | 26 | import sys
|
| 27 | +import asyncio |
| 28 | +from unittest.mock import Mock |
| 29 | +from pkg_resources import parse_version |
21 | 30 | import aiohttp
|
22 | 31 |
|
23 | 32 |
|
@@ -1038,3 +1047,49 @@ async def test_close_too_soon_works_fine(caplog, port, http_request):
|
1038 | 1047 | result = await transport.send(request)
|
1039 | 1048 |
|
1040 | 1049 | assert result # No exception is good enough here
|
| 1050 | + |
| 1051 | + |
| 1052 | +@pytest.mark.skipif( |
| 1053 | + parse_version(aiohttp.__version__) >= parse_version("3.10"), |
| 1054 | + reason="aiohttp 3.10 introduced separate connection timeout", |
| 1055 | +) |
| 1056 | +@pytest.mark.parametrize("http_request", HTTP_REQUESTS) |
| 1057 | +@pytest.mark.asyncio |
| 1058 | +async def test_aiohttp_timeout_response(http_request): |
| 1059 | + async with AioHttpTransport() as transport: |
| 1060 | + transport.session._connector.connect = Mock(side_effect=asyncio.TimeoutError("Too slow!")) |
| 1061 | + |
| 1062 | + request = http_request("GET", f"http://localhost:12345/basic/string") |
| 1063 | + |
| 1064 | + with pytest.raises(ServiceResponseTimeoutError) as err: |
| 1065 | + await transport.send(request) |
| 1066 | + |
| 1067 | + with pytest.raises(ServiceResponseError) as err: |
| 1068 | + await transport.send(request) |
| 1069 | + |
| 1070 | + stream_request = http_request("GET", f"http://localhost:12345/streams/basic") |
| 1071 | + with pytest.raises(ServiceResponseTimeoutError) as err: |
| 1072 | + await transport.send(stream_request, stream=True) |
| 1073 | + |
| 1074 | + |
| 1075 | +@pytest.mark.skipif( |
| 1076 | + parse_version(aiohttp.__version__) < parse_version("3.10"), |
| 1077 | + reason="aiohttp 3.10 introduced separate connection timeout", |
| 1078 | +) |
| 1079 | +@pytest.mark.parametrize("http_request", HTTP_REQUESTS) |
| 1080 | +@pytest.mark.asyncio |
| 1081 | +async def test_aiohttp_timeout_request(http_request): |
| 1082 | + async with AioHttpTransport() as transport: |
| 1083 | + transport.session._connector.connect = Mock(side_effect=asyncio.TimeoutError("Too slow!")) |
| 1084 | + |
| 1085 | + request = http_request("GET", f"http://localhost:12345/basic/string") |
| 1086 | + |
| 1087 | + with pytest.raises(ServiceRequestTimeoutError) as err: |
| 1088 | + await transport.send(request) |
| 1089 | + |
| 1090 | + with pytest.raises(ServiceRequestError) as err: |
| 1091 | + await transport.send(request) |
| 1092 | + |
| 1093 | + stream_request = http_request("GET", f"http://localhost:12345/streams/basic") |
| 1094 | + with pytest.raises(ServiceRequestTimeoutError) as err: |
| 1095 | + await transport.send(stream_request, stream=True) |
0 commit comments