Commits

Robert Brewer committed 932f0d6

Moved refleak test into its own module and added it to main test suite.

Comments (0)

Files changed (3)

cherrypy/test/test.py

     prefer_parent_path()
     
     testList = [
+        # Run refleak test ASAP to make debugging easier.
+        'test_refleaks',
+        
         'test_proxy',
         'test_caching',
         'test_config',

cherrypy/test/test_http.py

 from cherrypy.test import test
 test.prefer_parent_path()
 
-import gc
 import httplib
-import threading
 import cherrypy
-from cherrypy import _cprequest
 
 
-data = object()
-
-def get_instances(cls):
-    return [x for x in gc.get_objects() if isinstance(x, cls)]
-
 def setup_server():
     
     class Root:
         def index(self, *args, **kwargs):
-            cherrypy.request.thing = data
             return "Hello world!"
         index.exposed = True
-        
-        def gc_stats(self):
-            return "%s %s %s %s" % (gc.collect(),
-                                    len(get_instances(_cprequest.Request)),
-                                    len(get_instances(_cprequest.Response)),
-                                    len(gc.get_referrers(data)))
-        gc_stats.exposed = True
-        
-        def gc_objtypes(self):
-            data = {}
-            for x in gc.get_objects():
-                data[type(x)] = data.get(type(x), 0) + 1
-            
-            data = [(v, k) for k, v in data.iteritems()]
-            data.sort()
-            return "\n".join([repr(pair) for pair in data])
-        gc_objtypes.exposed = True
     
     cherrypy.tree.mount(Root())
     cherrypy.config.update({'environment': 'test_suite'})
         self.assertEqual(c.getresponse().status, 411)
 
 
-class ReferenceTests(helper.CPWebCase):
-    
-    def test_threadlocal_garbage(self):
-        def getpage():
-            self.getPage('/')
-            self.assertBody("Hello world!")
-        
-        ts = []
-        for _ in range(25):
-            t = threading.Thread(target=getpage)
-            ts.append(t)
-            t.start()
-        
-        for t in ts:
-            t.join()
-        
-        self.getPage("/gc_stats")
-        self.assertBody("0 1 1 1")
-        
-        # If gc_stats fails, choose "ignore" to see the type counts for
-        # all the unreachable objects in this body.
-        self.getPage("/gc_objtypes")
-        self.assertBody("")
-
-
 if __name__ == '__main__':
     setup_server()
     helper.testmain()

cherrypy/test/test_refleaks.py

+"""Tests for refleaks."""
+
+from cherrypy.test import test
+test.prefer_parent_path()
+
+import gc
+import threading
+import cherrypy
+from cherrypy import _cprequest
+
+
+data = object()
+
+def get_instances(cls):
+    return [x for x in gc.get_objects() if isinstance(x, cls)]
+
+def setup_server():
+    
+    class Root:
+        def index(self, *args, **kwargs):
+            cherrypy.request.thing = data
+            return "Hello world!"
+        index.exposed = True
+        
+        def gc_stats(self):
+            return "%s %s %s %s" % (gc.collect(),
+                                    len(get_instances(_cprequest.Request)),
+                                    len(get_instances(_cprequest.Response)),
+                                    len(gc.get_referrers(data)))
+        gc_stats.exposed = True
+        
+        def gc_objtypes(self):
+            data = {}
+            for x in gc.get_objects():
+                data[type(x)] = data.get(type(x), 0) + 1
+            
+            data = [(v, k) for k, v in data.iteritems()]
+            data.sort()
+            return "\n".join([repr(pair) for pair in data])
+        gc_objtypes.exposed = True
+    
+    cherrypy.tree.mount(Root())
+    cherrypy.config.update({'environment': 'test_suite'})
+
+
+from cherrypy.test import helper
+
+
+class ReferenceTests(helper.CPWebCase):
+    
+    def test_threadlocal_garbage(self):
+        def getpage():
+            self.getPage('/')
+            self.assertBody("Hello world!")
+        
+        ts = []
+        for _ in range(25):
+            t = threading.Thread(target=getpage)
+            ts.append(t)
+            t.start()
+        
+        for t in ts:
+            t.join()
+        
+        self.getPage("/gc_stats")
+        self.assertBody("0 1 1 1")
+        
+        # If gc_stats fails, choose "ignore" to see the type counts for
+        # all the unreachable objects in this body.
+        self.getPage("/gc_objtypes")
+        self.assertBody("")
+
+
+if __name__ == '__main__':
+    setup_server()
+    helper.testmain()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.