예제 #1
0
async def test_premature_response_close(server):
    """
    A premature close should close the connection.
    """
    async with http3.ConnectionPool() as http:
        response = await http.request("GET", "http://127.0.0.1:8000/")
        await response.close()
        assert len(http.active_connections) == 0
        assert len(http.keepalive_connections) == 0
예제 #2
0
async def test_standard_response_close(server):
    """
    A standard close should keep the connection open.
    """
    async with http3.ConnectionPool() as http:
        response = await http.request("GET", "http://127.0.0.1:8000/")
        await response.read()
        await response.close()
        assert len(http.active_connections) == 0
        assert len(http.keepalive_connections) == 1
예제 #3
0
async def test_close_connections(server):
    """
    Using a `Connection: close` header should close the connection.
    """
    headers = [(b"connection", b"close")]
    async with http3.ConnectionPool() as http:
        response = await http.request("GET",
                                      "http://127.0.0.1:8000/",
                                      headers=headers)
        await response.read()
        assert len(http.active_connections) == 0
        assert len(http.keepalive_connections) == 0
예제 #4
0
async def test_streaming_response_holds_connection(server):
    """
    A streaming request should hold the connection open until the response is read.
    """
    async with http3.ConnectionPool() as http:
        response = await http.request("GET", "http://127.0.0.1:8000/")
        assert len(http.active_connections) == 1
        assert len(http.keepalive_connections) == 0

        await response.read()

        assert len(http.active_connections) == 0
        assert len(http.keepalive_connections) == 1
예제 #5
0
async def test_keepalive_connections(server):
    """
    Connections should default to staying in a keep-alive state.
    """
    async with http3.ConnectionPool() as http:
        response = await http.request("GET", "http://127.0.0.1:8000/")
        await response.read()
        assert len(http.active_connections) == 0
        assert len(http.keepalive_connections) == 1

        response = await http.request("GET", "http://127.0.0.1:8000/")
        await response.read()
        assert len(http.active_connections) == 0
        assert len(http.keepalive_connections) == 1
예제 #6
0
async def test_differing_connection_keys(server):
    """
    Connnections to differing connection keys should result in multiple connections.
    """
    async with http3.ConnectionPool() as http:
        response = await http.request("GET", "http://127.0.0.1:8000/")
        await response.read()
        assert len(http.active_connections) == 0
        assert len(http.keepalive_connections) == 1

        response = await http.request("GET", "http://localhost:8000/")
        await response.read()
        assert len(http.active_connections) == 0
        assert len(http.keepalive_connections) == 2
예제 #7
0
async def test_soft_limit(server):
    """
    The soft_limit config should limit the maximum number of keep-alive connections.
    """
    pool_limits = http3.PoolLimits(soft_limit=1)

    async with http3.ConnectionPool(pool_limits=pool_limits) as http:
        response = await http.request("GET", "http://127.0.0.1:8000/")
        await response.read()
        assert len(http.active_connections) == 0
        assert len(http.keepalive_connections) == 1

        response = await http.request("GET", "http://localhost:8000/")
        await response.read()
        assert len(http.active_connections) == 0
        assert len(http.keepalive_connections) == 1
예제 #8
0
async def test_multiple_concurrent_connections(server):
    """
    Multiple conncurrent requests should open multiple conncurrent connections.
    """
    async with http3.ConnectionPool() as http:
        response_a = await http.request("GET", "http://127.0.0.1:8000/")
        assert len(http.active_connections) == 1
        assert len(http.keepalive_connections) == 0

        response_b = await http.request("GET", "http://127.0.0.1:8000/")
        assert len(http.active_connections) == 2
        assert len(http.keepalive_connections) == 0

        await response_b.read()
        assert len(http.active_connections) == 1
        assert len(http.keepalive_connections) == 1

        await response_a.read()
        assert len(http.active_connections) == 0
        assert len(http.keepalive_connections) == 2
예제 #9
0
 def __init__(self):
     self.pool = http3.ConnectionPool()