Skip to content

Commit

Permalink
Added tests that check a connection timeout for all backends
Browse files Browse the repository at this point in the history
  • Loading branch information
cdeler committed Nov 26, 2020
1 parent a21e610 commit d003888
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/async_tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,33 @@ async def test_cannot_connect_uds(backend: str) -> None:
async with httpcore.AsyncConnectionPool(backend=backend, uds=uds) as http:
with pytest.raises(httpcore.ConnectError):
await http.arequest(method, url)


@pytest.mark.anyio
async def test_connection_timeout_tcp(backend: str, server: Server) -> None:
# we try to access http server using https. It caused some SSL timeouts
# in TLSStream.wrap inside inside AnyIOBackend.open_tcp_stream
method = b"GET"
url = (b"https", *server.netloc, b"/")
headers = [server.host_header]
ext = {"timeout": {"connect": 0.1}}

async with httpcore.AsyncConnectionPool(backend=backend) as http:
with pytest.raises(httpcore.ConnectTimeout):
await http.arequest(method, url, headers, ext=ext)


@pytest.mark.anyio
async def test_connection_timeout_uds(
backend: str, uds_server: Server, uds: str
) -> None:
# we try to access http server using https. It caused some SSL timeouts
# in TLSStream.wrap inside AnyIOBackend.open_uds_stream
method = b"GET"
url = (b"https", b"localhost", None, b"/")
headers = [(b"host", b"localhost")]
ext = {"timeout": {"connect": 0.1}}

async with httpcore.AsyncConnectionPool(uds=uds, backend=backend) as http:
with pytest.raises(httpcore.ConnectTimeout):
await http.arequest(method, url, headers, ext=ext)
30 changes: 30 additions & 0 deletions tests/sync_tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,33 @@ def test_cannot_connect_uds(backend: str) -> None:
with httpcore.SyncConnectionPool(backend=backend, uds=uds) as http:
with pytest.raises(httpcore.ConnectError):
http.request(method, url)



def test_connection_timeout_tcp(backend: str, server: Server) -> None:
# we try to access http server using https. It caused some SSL timeouts
# in TLSStream.wrap inside inside AnyIOBackend.open_tcp_stream
method = b"GET"
url = (b"https", *server.netloc, b"/")
headers = [server.host_header]
ext = {"timeout": {"connect": 0.1}}

with httpcore.SyncConnectionPool(backend=backend) as http:
with pytest.raises(httpcore.ConnectTimeout):
http.request(method, url, headers, ext=ext)



def test_connection_timeout_uds(
backend: str, uds_server: Server, uds: str
) -> None:
# we try to access http server using https. It caused some SSL timeouts
# in TLSStream.wrap inside AnyIOBackend.open_uds_stream
method = b"GET"
url = (b"https", b"localhost", None, b"/")
headers = [(b"host", b"localhost")]
ext = {"timeout": {"connect": 0.1}}

with httpcore.SyncConnectionPool(uds=uds, backend=backend) as http:
with pytest.raises(httpcore.ConnectTimeout):
http.request(method, url, headers, ext=ext)

0 comments on commit d003888

Please sign in to comment.