Skip to content

Commit

Permalink
Add test for Pool.__del__
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Apr 22, 2015
1 parent 1a847cc commit d56281c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aiopg/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def __iter__(self):
conn = yield from self.acquire()
return _ConnectionContextManager(self, conn)

if PY_34:
if PY_34: # pragma: no branch
def __del__(self):
try:
self._free
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,17 @@ def go():
self.assertEqual(item, tst)

self.loop.run_until_complete(go())

def test_echo_callproc(self):
@asyncio.coroutine
def go():
conn = yield from self.connect(echo=True)
cur = yield from conn.cursor()

# TODO: check log records
yield from cur.callproc('inc', [1])
ret = yield from cur.fetchone()
self.assertEqual((2,), ret)
cur.close()

self.loop.run_until_complete(go())
13 changes: 13 additions & 0 deletions tests/test_pool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import unittest
from unittest import mock
import sys

from psycopg2.extensions import TRANSACTION_STATUS_INTRANS

Expand Down Expand Up @@ -526,3 +527,15 @@ def go():
0.1, loop=self.loop)

self.loop.run_until_complete(go())

@unittest.skipIf(sys.version_info < (3, 4),
"Python 3.3 doesnt support __del__ calls from GC")
def test___del__(self):
@asyncio.coroutine
def go():
pool = yield from self.create_pool()
self.pool = None # drop reference
with self.assertWarns(ResourceWarning):
del pool

self.loop.run_until_complete(go())

0 comments on commit d56281c

Please sign in to comment.