Changeset 879 for trunk/tests


Ignore:
Timestamp:
Jul 23, 2016, 8:06:19 AM (3 years ago)
Author:
cito
Message:

Enable garbage collection after closing DB instance

Note that there is still a problem if the DB instance is not closed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/test_classic_dbwrapper.py

    r878 r879  
    1818import os
    1919import sys
     20import gc
    2021import json
    2122import tempfile
     
    44454446
    44464447
     4448class TestMemoryLeaks(unittest.TestCase):
     4449    """Test that the DB class does not leak memory."""
     4450
     4451    def getLeaks(self, fut):
     4452        ids = set()
     4453        objs = []
     4454        add_ids = ids.update
     4455        gc.collect()
     4456        objs[:] = gc.get_objects()
     4457        add_ids(id(obj) for obj in objs)
     4458        fut()
     4459        gc.collect()
     4460        objs[:] = gc.get_objects()
     4461        objs[:] = [obj for obj in objs if id(obj) not in ids]
     4462        self.assertEqual(len(objs), 0)
     4463
     4464    def testLeaksWithClose(self):
     4465        def fut():
     4466            db = DB()
     4467            db.query("select $1::int as r", 42).dictresult()
     4468            db.close()
     4469            del db
     4470        self.getLeaks(fut)
     4471
     4472    @unittest.skip("this still needs to be resolved")
     4473    def testLeaksWithoutClose(self):
     4474        def fut():
     4475            db = DB()
     4476            db.query("select $1::int as r", 42).dictresult()
     4477        self.getLeaks(fut)
     4478
     4479
    44474480if __name__ == '__main__':
    44484481    unittest.main()
Note: See TracChangeset for help on using the changeset viewer.