Skip to content

Commit 91ecdf8

Browse files
author
James William Pye
committed
Add basic test for GC.
Make sure that the weakref callback is getting called.
1 parent b1be79c commit 91ecdf8

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

postgresql/test/test_driver.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import time
1010
import datetime
1111
import decimal
12+
import gc
1213
from itertools import chain, islice
1314
from operator import itemgetter
1415

@@ -317,6 +318,27 @@ def testItsClosed(self):
317318
c.close()
318319
self.db.close()
319320

321+
def testGarbage(self):
322+
ps = self.db.prepare('select 1')
323+
sid = ps.statement_id
324+
ci = ps.chunks()
325+
ci_id = ci.cursor.cursor_id
326+
c = ps.declare()
327+
cid = c.cursor_id
328+
# make sure there are no remaining xact references..
329+
self.db._pq_complete()
330+
# ci and c both hold references to ps, so they must
331+
# be removed before we can observe the effects __del__
332+
del c
333+
gc.collect()
334+
self.failUnless(self.db.typio.encode(cid) in self.db._closeportals)
335+
del ci
336+
gc.collect()
337+
self.failUnless(self.db.typio.encode(ci_id) in self.db._closeportals)
338+
del ps
339+
gc.collect()
340+
self.failUnless(self.db.typio.encode(sid) in self.db._closestatements)
341+
320342
def testStatementCall(self):
321343
ps = self.db.prepare("SELECT 1")
322344
r = ps()

0 commit comments

Comments
 (0)