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

Changeset 1019

Show
Ignore:
Timestamp:
03/28/06 12:20:46
Author:
fumanchu
Message:

Re-org of test_http to fit new separate-client-and-server design of test suite.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/test/test_http.py

    r1017 r1019  
    1818data = object() 
    1919 
     20def get_instances(cls): 
     21    return [x for x in gc.get_objects() if isinstance(x, cls)] 
     22 
    2023def setup_server(): 
     24     
    2125    class Root: 
    2226        def index(self, *args, **kwargs): 
     
    2428            return "Hello world!" 
    2529        index.exposed = True 
     30         
     31        def gc_stats(self): 
     32            return "%s %s %s %s" % (gc.collect(), 
     33                                    len(get_instances(_cphttptools.Request)), 
     34                                    len(get_instances(_cphttptools.Response)), 
     35                                    len(gc.get_referrers(data))) 
     36        gc_stats.exposed = True 
    2637    cherrypy.tree.mount(Root()) 
    27  
     38     
    2839    cherrypy.config.update({ 
    2940        'global': {'server.log_to_screen': False, 
     
    3950     
    4051    def test_sockets(self): 
    41         if cherrypy.server.httpserver: 
    42             # By not including a Content-Length header, cgi.FieldStorage 
    43             # will hang. Verify that CP times out the socket and responds 
    44             # with 411 Length Required. 
    45             c = httplib.HTTPConnection("localhost:%s" % self.PORT) 
    46             c.request("POST", "/") 
    47             self.assertEqual(c.getresponse().status, 411) 
    48  
    49  
    50 def get_instances(cls): 
    51     return [x for x in gc.get_objects() if isinstance(x, cls)] 
     52        # By not including a Content-Length header, cgi.FieldStorage 
     53        # will hang. Verify that CP times out the socket and responds 
     54        # with 411 Length Required. 
     55        c = httplib.HTTPConnection("localhost:%s" % self.PORT) 
     56        c.request("POST", "/") 
     57        self.assertEqual(c.getresponse().status, 411) 
    5258 
    5359 
     
    6066         
    6167        ts = [] 
    62         for _ in range(100): 
     68        for _ in range(25): 
    6369            t = threading.Thread(target=getpage) 
    6470            ts.append(t) 
     
    6874            t.join() 
    6975         
    70         self.assertEqual(gc.collect(), 0) 
    71         self.assertEqual(len(get_instances(_cphttptools.Request)), 0) 
    72         self.assertEqual(len(get_instances(_cphttptools.Response)), 0) 
    73         self.assertEqual(len(gc.get_referrers(data)), 1) 
     76        self.getPage("/gc_stats") 
     77        self.assertBody("0 1 1 1") 
    7478 
    7579 

Hosted by WebFaction

Log in as guest/cpguest to create tickets