Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1710

Show
Ignore:
Timestamp:
08/24/07 12:40:21
Author:
fumanchu
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/cherrypy-3.0.x/cherrypy/test/test.py

    r1528 r1710  
    355355     
    356356    testList = [ 
     357        # Run refleak test ASAP to make debugging easier. 
     358        'test_refleaks', 
     359         
    357360        'test_proxy', 
    358361        'test_caching', 
  • branches/cherrypy-3.0.x/cherrypy/test/test_http.py

    r1709 r1710  
    99test.prefer_parent_path() 
    1010 
    11 import gc 
    1211import httplib 
    13 import threading 
    1412import cherrypy 
    15 from cherrypy import _cprequest 
    1613 
    17  
    18 data = object() 
    19  
    20 def get_instances(cls): 
    21     return [x for x in gc.get_objects() if isinstance(x, cls)] 
    2214 
    2315def setup_server(): 
     
    2517    class Root: 
    2618        def index(self, *args, **kwargs): 
    27             cherrypy.request.thing = data 
    2819            return "Hello world!" 
    2920        index.exposed = True 
    30          
    31         def gc_stats(self): 
    32             return "%s %s %s %s" % (gc.collect(), 
    33                                     len(get_instances(_cprequest.Request)), 
    34                                     len(get_instances(_cprequest.Response)), 
    35                                     len(gc.get_referrers(data))) 
    36         gc_stats.exposed = True 
    37          
    38         def gc_objtypes(self): 
    39             data = {} 
    40             for x in gc.get_objects(): 
    41                 data[type(x)] = data.get(type(x), 0) + 1 
    42              
    43             data = [(v, k) for k, v in data.iteritems()] 
    44             data.sort() 
    45             return "\n".join([repr(pair) for pair in data]) 
    46         gc_objtypes.exposed = True 
    4721     
    4822    cherrypy.tree.mount(Root()) 
     
    6337 
    6438 
    65 class ReferenceTests(helper.CPWebCase): 
    66      
    67     def test_threadlocal_garbage(self): 
    68         def getpage(): 
    69             self.getPage('/') 
    70             self.assertBody("Hello world!") 
    71          
    72         ts = [] 
    73         for _ in range(25): 
    74             t = threading.Thread(target=getpage) 
    75             ts.append(t) 
    76             t.start() 
    77          
    78         for t in ts: 
    79             t.join() 
    80          
    81         self.getPage("/gc_stats") 
    82         self.assertBody("0 1 1 1") 
    83          
    84         # If gc_stats fails, choose "ignore" to see the type counts for 
    85         # all the unreachable objects in this body. 
    86         self.getPage("/gc_objtypes") 
    87         self.assertBody("") 
    88  
    89  
    9039if __name__ == '__main__': 
    9140    setup_server() 

Hosted by WebFaction

Log in as guest/cpguest to create tickets