@@ -290,7 +290,6 @@ async def test_create_conn() -> None:
290
290
conn = aiohttp .BaseConnector ()
291
291
with pytest .raises (NotImplementedError ):
292
292
await conn ._create_connection (object (), [], object ()) # type: ignore[arg-type]
293
-
294
293
await conn .close ()
295
294
296
295
@@ -318,80 +317,90 @@ async def test_close(key: ConnectionKey) -> None:
318
317
319
318
async def test_get (loop : asyncio .AbstractEventLoop , key : ConnectionKey ) -> None :
320
319
conn = aiohttp .BaseConnector ()
321
- assert await conn ._get (key , []) is None
320
+ try :
321
+ assert await conn ._get (key , []) is None
322
322
323
- proto = create_mocked_conn (loop )
324
- conn ._conns [key ] = deque ([(proto , loop .time ())])
325
- connection = await conn ._get (key , [])
326
- assert connection is not None
327
- assert connection .protocol == proto
328
- connection .close ()
329
- await conn .close ()
323
+ proto = create_mocked_conn (loop )
324
+ conn ._conns [key ] = deque ([(proto , loop .time ())])
325
+ connection = await conn ._get (key , [])
326
+ assert connection is not None
327
+ assert connection .protocol == proto
328
+ connection .close ()
329
+ finally :
330
+ await conn .close ()
330
331
331
332
332
333
async def test_get_unconnected_proto (loop : asyncio .AbstractEventLoop ) -> None :
333
334
conn = aiohttp .BaseConnector ()
334
335
key = ConnectionKey ("localhost" , 80 , False , False , None , None , None )
335
- assert await conn ._get (key , []) is None
336
+ try :
337
+ assert await conn ._get (key , []) is None
336
338
337
- proto = create_mocked_conn (loop )
338
- conn ._conns [key ] = deque ([(proto , loop .time ())])
339
- connection = await conn ._get (key , [])
340
- assert connection is not None
341
- assert connection .protocol == proto
342
- connection .close ()
339
+ proto = create_mocked_conn (loop )
340
+ conn ._conns [key ] = deque ([(proto , loop .time ())])
341
+ connection = await conn ._get (key , [])
342
+ assert connection is not None
343
+ assert connection .protocol == proto
344
+ connection .close ()
343
345
344
- assert await conn ._get (key , []) is None
345
- conn ._conns [key ] = deque ([(proto , loop .time ())])
346
- proto .is_connected = lambda * args : False
347
- assert await conn ._get (key , []) is None
348
- await conn .close ()
346
+ assert await conn ._get (key , []) is None
347
+ conn ._conns [key ] = deque ([(proto , loop .time ())])
348
+ proto .is_connected = lambda * args : False
349
+ assert await conn ._get (key , []) is None
350
+ finally :
351
+ await conn .close ()
349
352
350
353
351
354
async def test_get_unconnected_proto_ssl (loop : asyncio .AbstractEventLoop ) -> None :
352
355
conn = aiohttp .BaseConnector ()
353
356
key = ConnectionKey ("localhost" , 80 , True , False , None , None , None )
354
- assert await conn ._get (key , []) is None
357
+ try :
358
+ assert await conn ._get (key , []) is None
355
359
356
- proto = create_mocked_conn (loop )
357
- conn ._conns [key ] = deque ([(proto , loop .time ())])
358
- connection = await conn ._get (key , [])
359
- assert connection is not None
360
- assert connection .protocol == proto
361
- connection .close ()
360
+ proto = create_mocked_conn (loop )
361
+ conn ._conns [key ] = deque ([(proto , loop .time ())])
362
+ connection = await conn ._get (key , [])
363
+ assert connection is not None
364
+ assert connection .protocol == proto
365
+ connection .close ()
362
366
363
- assert await conn ._get (key , []) is None
364
- conn ._conns [key ] = deque ([(proto , loop .time ())])
365
- proto .is_connected = lambda * args : False
366
- assert await conn ._get (key , []) is None
367
- await conn .close ()
367
+ assert await conn ._get (key , []) is None
368
+ conn ._conns [key ] = deque ([(proto , loop .time ())])
369
+ proto .is_connected = lambda * args : False
370
+ assert await conn ._get (key , []) is None
371
+ finally :
372
+ await conn .close ()
368
373
369
374
370
375
async def test_get_expired (loop : asyncio .AbstractEventLoop ) -> None :
371
376
conn = aiohttp .BaseConnector ()
372
377
key = ConnectionKey ("localhost" , 80 , False , False , None , None , None )
373
- assert await conn ._get (key , []) is None
378
+ try :
379
+ assert await conn ._get (key , []) is None
374
380
375
- proto = create_mocked_conn (loop )
376
- conn ._conns [key ] = deque ([(proto , loop .time () - 1000 )])
377
- assert await conn ._get (key , []) is None
378
- assert not conn ._conns
379
- await conn .close ()
381
+ proto = create_mocked_conn (loop )
382
+ conn ._conns [key ] = deque ([(proto , loop .time () - 1000 )])
383
+ assert await conn ._get (key , []) is None
384
+ assert not conn ._conns
385
+ finally :
386
+ await conn .close ()
380
387
381
388
382
389
@pytest .mark .usefixtures ("enable_cleanup_closed" )
383
390
async def test_get_expired_ssl (loop : asyncio .AbstractEventLoop ) -> None :
384
391
conn = aiohttp .BaseConnector (enable_cleanup_closed = True )
385
392
key = ConnectionKey ("localhost" , 80 , True , False , None , None , None )
386
- assert await conn ._get (key , []) is None
393
+ try :
394
+ assert await conn ._get (key , []) is None
387
395
388
- proto = create_mocked_conn (loop )
389
- transport = proto .transport
390
- conn ._conns [key ] = deque ([(proto , loop .time () - 1000 )])
391
- assert await conn ._get (key , []) is None
392
- assert not conn ._conns
393
- assert conn ._cleanup_closed_transports == [transport ]
394
- await conn .close ()
396
+ proto = create_mocked_conn (loop )
397
+ transport = proto .transport
398
+ conn ._conns [key ] = deque ([(proto , loop .time () - 1000 )])
399
+ assert await conn ._get (key , []) is None
400
+ assert not conn ._conns
401
+ assert conn ._cleanup_closed_transports == [transport ]
402
+ finally :
403
+ await conn .close ()
395
404
396
405
397
406
async def test_release_acquired (key : ConnectionKey ) -> None :
0 commit comments