Changeset 881


Ignore:
Timestamp:
Jul 23, 2016, 3:41:16 PM (3 years ago)
Author:
cito
Message:

Add memory leak test for pgdb connections

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/docs/contents/changelog.rst

    r878 r881  
    1616- Allow extra values that are not used in the command in the parameter dict
    1717  passed to the query_formatted() method (as suggested by Justin Pryzby).
     18- Unused classic connections were not properly garbage collected which could
     19  cause memory leaks (reported by Justin Pryby).
    1820- Made C extension compatible with MSVC 9 again (this was needed to compile for
    1921  Python 2 on Windows).
  • trunk/pgdb.py

    r876 r881  
    926926            if not self._dbcnx._tnx:
    927927                try:
    928                     self._cnx.source().execute(sql)
     928                    self._src.execute(sql)
    929929                except DatabaseError:
    930930                    raise  # database provides error message
  • trunk/tests/test_classic_dbwrapper.py

    r880 r881  
    929929        r = q.getresult()[0][0]
    930930        self.assertEqual(r, 'alphabetagammadeltaepsilon')
    931 
    932 
    933931
    934932    def testPkey(self):
     
    44604458        objs[:] = gc.get_objects()
    44614459        objs[:] = [obj for obj in objs if id(obj) not in ids]
     4460        if objs and sys.version_info[:3] in ((3, 5, 0), (3, 5, 1)):
     4461            # workaround for Python issue 26811
     4462            objs[:] = [obj for obj in objs if repr(obj) != '(<NULL>,)']
    44624463        self.assertEqual(len(objs), 0)
    44634464
  • trunk/tests/test_dbapi20.py

    r875 r881  
    2828    except ImportError:
    2929        pass
     30
     31import gc
     32import sys
    3033
    3134from datetime import date, time, datetime, timedelta
     
    12171220        self.assertNotEqual('_record', pgdb.RECORD)
    12181221
     1222    def test_no_close(self):
     1223        data = ('hello', 'world')
     1224        con = self._connect()
     1225        cur = con.cursor()
     1226        cur.build_row_factory = lambda: tuple
     1227        cur.execute("select %s, %s", data)
     1228        row = cur.fetchone()
     1229        self.assertEqual(row, data)
     1230
     1231    def test_memory_leaks(self):
     1232        ids = set()
     1233        objs = []
     1234        add_ids = ids.update
     1235        gc.collect()
     1236        objs[:] = gc.get_objects()
     1237        add_ids(id(obj) for obj in objs)
     1238        self.test_no_close()
     1239        gc.collect()
     1240        objs[:] = gc.get_objects()
     1241        objs[:] = [obj for obj in objs if id(obj) not in ids]
     1242        if objs and sys.version_info[:3] in ((3, 5, 0), (3, 5, 1)):
     1243            # workaround for Python issue 26811
     1244            objs[:] = [obj for obj in objs if repr(obj) != '(<NULL>,)']
     1245        self.assertEqual(len(objs), 0)
     1246
    12191247
    12201248if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.