Skip to content

Commit 2f4fe53

Browse files
committed
Fix a bunch of ResourceWarnings in the test suite
Make sure things get freed properly otherwise Python gets unhappy with ResourceWarnings.
1 parent 3a90fef commit 2f4fe53

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

asyncpg/_testbase/fuzzer.py

+6
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ async def handle(self):
191191
return_when=asyncio.FIRST_COMPLETED)
192192

193193
finally:
194+
if self.proxy_to_backend_task is not None:
195+
self.proxy_to_backend_task.cancel()
196+
197+
if self.proxy_from_backend_task is not None:
198+
self.proxy_from_backend_task.cancel()
199+
194200
# Asyncio fails to properly remove the readers and writers
195201
# when the task doing recv() or send() is cancelled, so
196202
# we must remove the readers and writers manually before

asyncpg/protocol/protocol.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ cdef class BaseProtocol(CoreProtocol):
609609
pass
610610
finally:
611611
self.waiter = None
612-
self.transport.abort()
612+
self.transport.abort()
613613

614614
def _request_cancel(self):
615615
self.cancel_waiter = self.create_future()

tests/test_connect.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1604,11 +1604,14 @@ async def test_nossl_connection_prefer_cancel(self):
16041604
dsn='postgresql://foo/postgres?sslmode=prefer',
16051605
host='localhost',
16061606
user='ssl_user')
1607-
self.assertFalse(con._protocol.is_ssl)
1608-
with self.assertRaises(asyncio.TimeoutError):
1609-
await con.execute('SELECT pg_sleep(5)', timeout=0.5)
1610-
val = await con.fetchval('SELECT 123')
1611-
self.assertEqual(val, 123)
1607+
try:
1608+
self.assertFalse(con._protocol.is_ssl)
1609+
with self.assertRaises(asyncio.TimeoutError):
1610+
await con.execute('SELECT pg_sleep(5)', timeout=0.5)
1611+
val = await con.fetchval('SELECT 123')
1612+
self.assertEqual(val, 123)
1613+
finally:
1614+
await con.close()
16121615

16131616
async def test_nossl_connection_pool(self):
16141617
pool = await self.create_pool(

tests/test_pool.py

+3
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ async def test_pool_expire_connections(self):
842842
await pool.release(con)
843843

844844
self.assertIsNone(pool._holders[0]._con)
845+
await pool.close()
845846

846847
async def test_pool_set_connection_args(self):
847848
pool = await self.create_pool(database='postgres',
@@ -883,6 +884,8 @@ async def test_pool_set_connection_args(self):
883884
con = await pool.acquire()
884885
self.assertEqual(con.get_settings().application_name,
885886
'set_conn_args_test_2')
887+
await pool.release(con)
888+
await pool.close()
886889

887890
async def test_pool_init_race(self):
888891
pool = self.create_pool(database='postgres', min_size=1, max_size=1)

0 commit comments

Comments
 (0)