@@ -2002,6 +2002,104 @@ async def test_tcp_connector_ctor() -> None:
20022002 await conn .close ()
20032003
20042004
2005+ async def test_tcp_connector_ssl_shutdown_timeout (
2006+ loop : asyncio .AbstractEventLoop ,
2007+ ) -> None :
2008+ # Test default value
2009+ conn = aiohttp .TCPConnector ()
2010+ assert conn ._ssl_shutdown_timeout == 0.1
2011+ await conn .close ()
2012+
2013+ # Test custom value
2014+ conn = aiohttp .TCPConnector (ssl_shutdown_timeout = 1.0 )
2015+ assert conn ._ssl_shutdown_timeout == 1.0
2016+ await conn .close ()
2017+
2018+ # Test None value
2019+ conn = aiohttp .TCPConnector (ssl_shutdown_timeout = None )
2020+ assert conn ._ssl_shutdown_timeout is None
2021+ await conn .close ()
2022+
2023+
2024+ @pytest .mark .skipif (
2025+ sys .version_info < (3 , 11 ), reason = "ssl_shutdown_timeout requires Python 3.11+"
2026+ )
2027+ async def test_tcp_connector_ssl_shutdown_timeout_passed_to_create_connection (
2028+ loop : asyncio .AbstractEventLoop , start_connection : mock .AsyncMock
2029+ ) -> None :
2030+ # Test that ssl_shutdown_timeout is passed to create_connection for SSL connections
2031+ conn = aiohttp .TCPConnector (ssl_shutdown_timeout = 2.5 )
2032+
2033+ with mock .patch .object (
2034+ conn ._loop , "create_connection" , autospec = True , spec_set = True
2035+ ) as create_connection :
2036+ create_connection .return_value = mock .Mock (), mock .Mock ()
2037+
2038+ req = ClientRequest ("GET" , URL ("https://example.com" ), loop = loop )
2039+
2040+ with closing (await conn .connect (req , [], ClientTimeout ())):
2041+ assert create_connection .call_args .kwargs ["ssl_shutdown_timeout" ] == 2.5
2042+
2043+ await conn .close ()
2044+
2045+ # Test with None value
2046+ conn = aiohttp .TCPConnector (ssl_shutdown_timeout = None )
2047+
2048+ with mock .patch .object (
2049+ conn ._loop , "create_connection" , autospec = True , spec_set = True
2050+ ) as create_connection :
2051+ create_connection .return_value = mock .Mock (), mock .Mock ()
2052+
2053+ req = ClientRequest ("GET" , URL ("https://example.com" ), loop = loop )
2054+
2055+ with closing (await conn .connect (req , [], ClientTimeout ())):
2056+ # When ssl_shutdown_timeout is None, it should not be in kwargs
2057+ assert "ssl_shutdown_timeout" not in create_connection .call_args .kwargs
2058+
2059+ await conn .close ()
2060+
2061+ # Test that ssl_shutdown_timeout is NOT passed for non-SSL connections
2062+ conn = aiohttp .TCPConnector (ssl_shutdown_timeout = 2.5 )
2063+
2064+ with mock .patch .object (
2065+ conn ._loop , "create_connection" , autospec = True , spec_set = True
2066+ ) as create_connection :
2067+ create_connection .return_value = mock .Mock (), mock .Mock ()
2068+
2069+ req = ClientRequest ("GET" , URL ("http://example.com" ), loop = loop )
2070+
2071+ with closing (await conn .connect (req , [], ClientTimeout ())):
2072+ # For non-SSL connections, ssl_shutdown_timeout should not be passed
2073+ assert "ssl_shutdown_timeout" not in create_connection .call_args .kwargs
2074+
2075+ await conn .close ()
2076+
2077+
2078+ @pytest .mark .skipif (sys .version_info >= (3 , 11 ), reason = "Test for Python < 3.11" )
2079+ async def test_tcp_connector_ssl_shutdown_timeout_not_passed_pre_311 (
2080+ loop : asyncio .AbstractEventLoop , start_connection : mock .AsyncMock
2081+ ) -> None :
2082+ # Test that ssl_shutdown_timeout is NOT passed to create_connection on Python < 3.11
2083+ conn = aiohttp .TCPConnector (ssl_shutdown_timeout = 2.5 )
2084+
2085+ with mock .patch .object (
2086+ conn ._loop , "create_connection" , autospec = True , spec_set = True
2087+ ) as create_connection :
2088+ create_connection .return_value = mock .Mock (), mock .Mock ()
2089+
2090+ # Test with HTTPS
2091+ req = ClientRequest ("GET" , URL ("https://example.com" ), loop = loop )
2092+ with closing (await conn .connect (req , [], ClientTimeout ())):
2093+ assert "ssl_shutdown_timeout" not in create_connection .call_args .kwargs
2094+
2095+ # Test with HTTP
2096+ req = ClientRequest ("GET" , URL ("http://example.com" ), loop = loop )
2097+ with closing (await conn .connect (req , [], ClientTimeout ())):
2098+ assert "ssl_shutdown_timeout" not in create_connection .call_args .kwargs
2099+
2100+ await conn .close ()
2101+
2102+
20052103async def test_tcp_connector_allowed_protocols (loop : asyncio .AbstractEventLoop ) -> None :
20062104 conn = aiohttp .TCPConnector ()
20072105 assert conn .allowed_protocol_schema_set == {"" , "tcp" , "http" , "https" , "ws" , "wss" }
0 commit comments