[Zope-Checkins] SVN: Zope/trunk/lib/python/Testing/ZopeTestCase/ Made sure to close the REQUEST so as not to leak REQUEST._held.

Stefan H. Holek stefan at epy.co.at
Sat May 7 07:10:24 EDT 2005


Log message for revision 30298:
  Made sure to close the REQUEST so as not to leak REQUEST._held.
  Thanks to Sidnei da Silva.
  

Changed:
  U   Zope/trunk/lib/python/Testing/ZopeTestCase/base.py
  U   Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt
  U   Zope/trunk/lib/python/Testing/ZopeTestCase/testBaseTestCase.py

-=-
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/base.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/base.py	2005-05-07 00:44:45 UTC (rev 30297)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/base.py	2005-05-07 11:10:24 UTC (rev 30298)
@@ -35,6 +35,7 @@
 
 def close(app):
     '''Closes the app's ZODB connection.'''
+    app.REQUEST.close()
     connections.close(app._p_jar)
 
 
@@ -118,6 +119,8 @@
         '''Clears the fixture.'''
         if call_close_hook:
             self.beforeClose()
+        if connections.contains(self.app._p_jar):
+            self.app.REQUEST.close()
         self._close()
         self.logout()
         self.afterClear()

Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt	2005-05-07 00:44:45 UTC (rev 30297)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt	2005-05-07 11:10:24 UTC (rev 30298)
@@ -15,6 +15,8 @@
   connection pool depletion and subsequent hangs. Thanks to Balazs Ree.
 - Encapsulated the ConnectionRegistry in its own module, connections.py.
   Reusing the registry from other modules becomes a lot cleaner as a result.
+- Made sure to close the REQUEST so as not to leak REQUEST._held. Thanks
+  to Sidnei da Silva.
 
 0.9.6
 - Dropped support for Zope 2.5 as it lacks the setSecurityManager() API.

Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/testBaseTestCase.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/testBaseTestCase.py	2005-05-07 00:44:45 UTC (rev 30297)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/testBaseTestCase.py	2005-05-07 11:10:24 UTC (rev 30298)
@@ -283,23 +283,6 @@
         assert self.reg.contains(self.conns[2])
 
 
-class TestRequestVariables(base.TestCase):
-    '''Makes sure the REQUEST contains required variables'''
-
-    def testRequestVariables(self):
-        request = self.app.REQUEST
-        self.failIfEqual(request.get('SERVER_NAME', ''), '')
-        self.failIfEqual(request.get('SERVER_PORT', ''), '')
-        self.failIfEqual(request.get('REQUEST_METHOD', ''), '')
-        self.failIfEqual(request.get('URL', ''), '')
-        self.failIfEqual(request.get('SERVER_URL', ''), '')
-        self.failIfEqual(request.get('URL0', ''), '')
-        self.failIfEqual(request.get('URL1', ''), '')
-        self.failIfEqual(request.get('BASE0', ''), '')
-        self.failIfEqual(request.get('BASE1', ''), '')
-        self.failIfEqual(request.get('BASE2', ''), '')
-
-
 class TestListConverter(base.TestCase):
 
     def testList0(self):
@@ -337,6 +320,61 @@
         self.assertRaises(ValueError, utils.makelist, dummy())
 
 
+class TestRequestVariables(base.TestCase):
+    '''Makes sure the REQUEST contains required variables'''
+
+    def testRequestVariables(self):
+        request = self.app.REQUEST
+        self.failIfEqual(request.get('SERVER_NAME', ''), '')
+        self.failIfEqual(request.get('SERVER_PORT', ''), '')
+        self.failIfEqual(request.get('REQUEST_METHOD', ''), '')
+        self.failIfEqual(request.get('URL', ''), '')
+        self.failIfEqual(request.get('SERVER_URL', ''), '')
+        self.failIfEqual(request.get('URL0', ''), '')
+        self.failIfEqual(request.get('URL1', ''), '')
+        self.failIfEqual(request.get('BASE0', ''), '')
+        self.failIfEqual(request.get('BASE1', ''), '')
+        self.failIfEqual(request.get('BASE2', ''), '')
+
+
+import gc
+_sentinel1 = []
+
+class TestRequestGarbage1(base.TestCase):
+    '''Make sure we do not leak REQUEST._held (and REQUEST.other)'''
+
+    class Held:
+        def __del__(self):
+            _sentinel1.append('__del__')
+
+    def afterSetUp(self):
+        self.anApp = base.app()
+        self.anApp.REQUEST._hold(self.Held())
+
+    def testBaseCloseClosesRequest(self):
+        base.close(self.anApp)
+        gc.collect()
+        self.assertEqual(_sentinel1, ['__del__'])
+
+
+_sentinel2 = []
+
+class TestRequestGarbage2(base.TestCase):
+    '''Make sure we do not leak REQUEST._held (and REQUEST.other)'''
+
+    class Held:
+        def __del__(self):
+            _sentinel2.append('__del__')
+
+    def afterSetUp(self):
+        self.app.REQUEST._hold(self.Held())
+
+    def testClearClosesRequest(self):
+        self._clear()
+        gc.collect()
+        self.assertEqual(_sentinel2, ['__del__'])
+
+
 def test_suite():
     from unittest import TestSuite, makeSuite
     suite = TestSuite()
@@ -344,8 +382,10 @@
     suite.addTest(makeSuite(TestSetUpRaises))
     suite.addTest(makeSuite(TestTearDownRaises))
     suite.addTest(makeSuite(TestConnectionRegistry))
+    suite.addTest(makeSuite(TestListConverter))
     suite.addTest(makeSuite(TestRequestVariables))
-    suite.addTest(makeSuite(TestListConverter))
+    suite.addTest(makeSuite(TestRequestGarbage1))
+    suite.addTest(makeSuite(TestRequestGarbage2))
     return suite
 
 if __name__ == '__main__':



More information about the Zope-Checkins mailing list