Skip to content
Myr

test_concurrency.py

This file

Path

tests/test_concurrency.py

38 lines · 1.2 KiB · Python

Last changed by

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

History of this file

Take it

Add ConcurrencyBackend.start_tls() (#263)Seth Michael Larsonbefore adoption1872ae8

lines 1–21why, one step back
1import sys
23import pytest45from httpx import AsyncioBackend, HTTPVersionConfig, SSLConfig, TimeoutConfig678@pytest.mark.xfail(9 sys.version_info < (3, 7),10 reason="Requires Python 3.7+ for AbstractEventLoop.start_tls()",11)12@pytest.mark.asyncio13async def test_start_tls_on_socket_stream(https_server):14 """15 See that the backend can make a connection without TLS then16 start TLS on an existing connection.17 """18 backend = AsyncioBackend()19 ctx = SSLConfig().load_ssl_context_no_verify(HTTPVersionConfig())20 timeout = TimeoutConfig(5)21

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

lines 22–24why, one step back
22 stream = await backend.connect(
23 https_server.url.host, https_server.url.port, None, timeout24 )

Add ConcurrencyBackend.start_tls() (#263)Seth Michael Larsonbefore adoption1872ae8

line 25why, one step back
25

Serve test server in thread (#292)Florimond Mancabefore adoption994403b

lines 26–28why, one step back
26 try:
27 assert stream.is_connection_dropped() is False28 assert stream.stream_writer.get_extra_info("cipher", default=None) is None

Add ConcurrencyBackend.start_tls() (#263)Seth Michael Larsonbefore adoption1872ae8

line 29why, one step back
29

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 30why, one step back
30 stream = await backend.start_tls(stream, https_server.url.host, ctx, timeout)

Serve test server in thread (#292)Florimond Mancabefore adoption994403b

lines 31–38why, one step back
31 assert stream.is_connection_dropped() is False
32 assert stream.stream_writer.get_extra_info("cipher", default=None) is not None3334 await stream.write(b"GET / HTTP/1.1\r\n\r\n")35 assert (await stream.read(8192, timeout)).startswith(b"HTTP/1.1 200 OK\r\n")3637 finally:38 await stream.close()