Skip to content

Commit 9ac7991

Browse files
committed
More robust work-around for ResourceWarnings
The sleep wasn't reliably long-enough, but requesting the client to close the connection reliably avoids the issue. As suggested here: aio-libs/aiohttp#1925 (comment)
1 parent be00a60 commit 9ac7991

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

tests/test_api.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import importlib
32
import os
43
import platform
@@ -300,13 +299,14 @@ def test_sslcontext_api_success(host):
300299
@pytest.mark.asyncio
301300
async def test_sslcontext_api_success_async(host):
302301
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:
304306
resp = await http.request("GET", f"https://{host}", ssl=ctx)
305307

306308
assert resp.status == 200
307309
assert len(await resp.text()) > 0
308-
# workaround https://github.com/aio-libs/aiohttp/issues/5426
309-
await asyncio.sleep(0.2)
310310

311311

312312
@failure_hosts
@@ -328,15 +328,15 @@ async def test_sslcontext_api_failures_async(failure):
328328
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
329329
if platform.system() != "Linux":
330330
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:
332335
with pytest.raises(
333336
aiohttp.client_exceptions.ClientConnectorCertificateError
334337
) as e:
335338
await http.request("GET", f"https://{failure.host}", ssl=ctx)
336339

337-
# workaround https://github.com/aio-libs/aiohttp/issues/5426
338-
await asyncio.sleep(0.2)
339-
340340
assert "cert" in repr(e.value).lower() and "verif" in repr(e.value).lower()
341341

342342

0 commit comments

Comments
 (0)