1
- import asyncio
2
1
import importlib
3
2
import os
4
3
import platform
@@ -300,13 +299,14 @@ def test_sslcontext_api_success(host):
300
299
@pytest .mark .asyncio
301
300
async def test_sslcontext_api_success_async (host ):
302
301
ctx = truststore .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
303
- async with aiohttp .ClientSession () as http :
302
+ # connector avoids https://github.com/aio-libs/aiohttp/issues/5426
303
+ async with aiohttp .ClientSession (
304
+ connector = aiohttp .TCPConnector (force_close = True , enable_cleanup_closed = True )
305
+ ) as http :
304
306
resp = await http .request ("GET" , f"https://{ host } " , ssl = ctx )
305
307
306
308
assert resp .status == 200
307
309
assert len (await resp .text ()) > 0
308
- # workaround https://github.com/aio-libs/aiohttp/issues/5426
309
- await asyncio .sleep (0.2 )
310
310
311
311
312
312
@failure_hosts
@@ -328,15 +328,15 @@ async def test_sslcontext_api_failures_async(failure):
328
328
ctx = truststore .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
329
329
if platform .system () != "Linux" :
330
330
ctx .verify_flags |= ssl .VERIFY_CRL_CHECK_CHAIN
331
- async with aiohttp .ClientSession () as http :
331
+ # connector avoids https://github.com/aio-libs/aiohttp/issues/5426
332
+ async with aiohttp .ClientSession (
333
+ connector = aiohttp .TCPConnector (force_close = True , enable_cleanup_closed = True )
334
+ ) as http :
332
335
with pytest .raises (
333
336
aiohttp .client_exceptions .ClientConnectorCertificateError
334
337
) as e :
335
338
await http .request ("GET" , f"https://{ failure .host } " , ssl = ctx )
336
339
337
- # workaround https://github.com/aio-libs/aiohttp/issues/5426
338
- await asyncio .sleep (0.2 )
339
-
340
340
assert "cert" in repr (e .value ).lower () and "verif" in repr (e .value ).lower ()
341
341
342
342
0 commit comments