File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -379,6 +379,26 @@ async def worker():
379
379
self .cluster .trust_local_connections ()
380
380
self .cluster .reload ()
381
381
382
+ async def test_pool_handles_task_cancel_in_acquire_with_timeout (self ):
383
+ # See https://github.com/MagicStack/asyncpg/issues/547
384
+ pool = await self .create_pool (database = 'postgres' ,
385
+ min_size = 1 , max_size = 1 )
386
+
387
+ async def worker ():
388
+ async with pool .acquire (timeout = 100 ):
389
+ pass
390
+
391
+ # Schedule task
392
+ task = self .loop .create_task (worker ())
393
+ # Yield to task, but cancel almost immediately
394
+ await asyncio .sleep (0.00000000001 )
395
+ # Cancel the worker.
396
+ task .cancel ()
397
+ # Wait to make sure the cleanup has completed.
398
+ await asyncio .sleep (0.4 )
399
+ # Check that the connection has been returned to the pool.
400
+ self .assertEqual (pool ._queue .qsize (), 1 )
401
+
382
402
async def test_pool_handles_task_cancel_in_release (self ):
383
403
# Use SlowResetConnectionPool to simulate
384
404
# the Task.cancel() and __aexit__ race.
You can’t perform that action at this time.
0 commit comments