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

Changeset 1255

Show
Ignore:
Timestamp:
08/20/06 15:51:30
Author:
fumanchu
Message:

More tests for persistent connections, including pipelining.

Files:

Legend:

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

    r1251 r1255  
    185185        assert self.concurrency > 0 
    186186        assert self.requests > 0 
    187         return ("-n %s -c %s http://localhost:%s%s" % 
     187        return ("-k -n %s -c %s http://localhost:%s%s" % 
    188188                (self.requests, self.concurrency, port, self.path)) 
    189189     
  • trunk/cherrypy/test/test.py

    r1252 r1255  
    308308        'test_caching', 
    309309        'test_config', 
     310        'test_conn', 
    310311        'test_core', 
    311312        'test_tools', 
  • trunk/cherrypy/test/test_conn.py

    r1253 r1255  
    1919        page2 = index 
    2020        page3 = index 
     21         
     22        def hello(self): 
     23            return "Hello, world!" 
     24        hello.exposed = True 
    2125         
    2226        def stream(self): 
     
    4246        # Set our HTTP_CONN to an instance so it persists between requests. 
    4347        self.HTTP_CONN = httplib.HTTPConnection(self.HOST, self.PORT) 
     48        # Don't automatically re-connect 
     49        self.HTTP_CONN.auto_open = False 
     50        self.HTTP_CONN.connect() 
    4451         
    4552        # Make the first request and assert there's no "Connection: close". 
     
    5663         
    5764        # Make another, streamed request on the same connection. 
     65        # Streamed output closes the connection to determine transfer-length. 
    5866        self.getPage("/stream") 
    5967        self.assertStatus('200 OK') 
    6068        self.assertBody('0123456789') 
    61         # Streamed output closes the connection to determine transfer-length. 
    6269        self.assertHeader("Connection", "close") 
    6370         
    64         # Make another request on a new connection, but close it. 
     71        # Make another request on the same connection, which should error. 
     72        self.assertRaises(httplib.NotConnected, self.getPage, "/") 
     73         
     74        # Test client-side close. 
    6575        self.HTTP_CONN = httplib.HTTPConnection(self.HOST, self.PORT) 
    6676        self.getPage("/page2", headers=[("Connection", "close")]) 
     
    6878        self.assertBody(pov) 
    6979        self.assertHeader("Connection", "close") 
     80     
     81    def test_HTTP11_pipelining(self): 
     82        # Test pipelining. httplib doesn't support this directly. 
     83        conn = httplib.HTTPConnection(self.HOST, self.PORT) 
     84        conn.auto_open = False 
     85        conn.connect() 
    7086         
    71         # Make another request on the same connection, which should error. 
    72         # This doesn't work with httplib, because it spawns a new socket as needed. 
    73 ##        self.assertRaises(socket.timeout, self.getPage, "/") 
     87        # Put request 1 
     88        conn.putrequest("GET", "/", skip_host=True) 
     89        conn.putheader("Host", self.HOST) 
     90        conn.endheaders() 
    7491         
    75         # XXX Test pipelining. httplib doesn't support this. 
     92        # Put request 2 
     93        conn._output('GET /hello HTTP/1.1') 
     94        conn._output("Host: %s" % self.HOST) 
     95        conn._send_output() 
    7696         
     97        # Retrieve response 1 
     98        response = conn.response_class(conn.sock, method="GET") 
     99        response.begin() 
     100        body = response.read() 
     101        self.assertEqual(response.status, 200) 
     102        self.assertEqual(body, pov) 
    77103         
     104        # Retrieve response 2 
     105        response = conn.response_class(conn.sock, method="GET") 
     106        response.begin() 
     107        body = response.read() 
     108        self.assertEqual(response.status, 200) 
     109        self.assertEqual(body, "Hello, world!") 
     110         
     111        conn.close() 
     112     
    78113    def test_HTTP10(self): 
    79114        self.PROTOCOL = "HTTP/1.1" 

Hosted by WebFaction

Log in as guest/cpguest to create tickets