@@ -571,6 +571,68 @@ async def test_connection_pool_timeout():
571571 await pool .request ("GET" , "https://example.com/" , extensions = extensions )
572572
573573
574+ @pytest .mark .anyio
575+ async def test_connection_pool_timeout_zero ():
576+ """
577+ A pool timeout of 0 shouldn't raise a PoolTimeout if there's
578+ no need to wait on a new connection.
579+ """
580+ network_backend = AsyncMockBackend (
581+ [
582+ b"HTTP/1.1 200 OK\r \n " ,
583+ b"Content-Type: plain/text\r \n " ,
584+ b"Content-Length: 13\r \n " ,
585+ b"\r \n " ,
586+ b"Hello, world!" ,
587+ b"HTTP/1.1 200 OK\r \n " ,
588+ b"Content-Type: plain/text\r \n " ,
589+ b"Content-Length: 13\r \n " ,
590+ b"\r \n " ,
591+ b"Hello, world!" ,
592+ ]
593+ )
594+
595+ # Use a pool timeout of zero.
596+ extensions = {"timeout" : {"pool" : 0 }}
597+
598+ # A connection pool configured to allow only one connection at a time.
599+ async with AsyncConnectionPool (
600+ network_backend = network_backend , max_connections = 1
601+ ) as pool :
602+ # Two consecutive requests with a pool timeout of zero.
603+ # Both succeed without raising a timeout.
604+ response = await pool .request (
605+ "GET" , "https://example.com/" , extensions = extensions
606+ )
607+ assert response .status == 200
608+ assert response .content == b"Hello, world!"
609+
610+ response = await pool .request (
611+ "GET" , "https://example.com/" , extensions = extensions
612+ )
613+ assert response .status == 200
614+ assert response .content == b"Hello, world!"
615+
616+ # A connection pool configured to allow only one connection at a time.
617+ async with AsyncConnectionPool (
618+ network_backend = network_backend , max_connections = 1
619+ ) as pool :
620+ # Two concurrent requests with a pool timeout of zero.
621+ # Only the first will succeed without raising a timeout.
622+ async with pool .stream (
623+ "GET" , "https://example.com/" , extensions = extensions
624+ ) as response :
625+ # The first response hasn't yet completed.
626+ with pytest .raises (PoolTimeout ):
627+ # So a pool timeout occurs.
628+ await pool .request ("GET" , "https://example.com/" , extensions = extensions )
629+ # The first response now completes.
630+ await response .aread ()
631+
632+ assert response .status == 200
633+ assert response .content == b"Hello, world!"
634+
635+
574636@pytest .mark .anyio
575637async def test_http11_upgrade_connection ():
576638 """
0 commit comments