Robert Brewer avatar Robert Brewer committed 589af3c

WOOHOO. Fixed test_conn on nix.

Comments (0)

Files changed (2)

cherrypy/test/helper.py

     """Run __main__ as a test module, with webtest debugging."""
     if '--server' in sys.argv:
         # Run the test module server-side only; wait for Ctrl-C to break.
-        if conf is None:
-            conf = {'server.socket_host': '0.0.0.0'}
+        conf = conf or {}
+        conf['server.socket_host'] = '0.0.0.0'
         setConfig(conf)
         cherrypy.engine.start()
         cherrypy.engine.block()
                 break
         else:
             # Run normally (both server and client in same process).
-            if conf is None:
-                conf = {'server.socket_host': '127.0.0.1'}
+            conf = conf or {}
+            conf['server.socket_host'] = '127.0.0.1'
             setConfig(conf)
             cherrypy.engine.start_with_callback(_test_main_thread)
             cherrypy.engine.block()

cherrypy/test/test_conn.py

 import socket
 import sys
 import time
-timeout = 0.1
+timeout = 1
 
 
 import cherrypy
         response.begin()
         self.assertEqual(response.status, 200)
         self.body = response.read()
-        self.assertBody("0.1")
+        self.assertBody(str(timeout))
         
         # Make a second request on the same socket
         conn._output('GET /hello HTTP/1.1')
         self.assertBody("Hello, world!")
         
         # Wait for our socket timeout
-        time.sleep(timeout * 10)
+        time.sleep(timeout * 2)
         
         # Make another request on the same socket, which should error
         conn._output('GET /hello HTTP/1.1')
                 self.fail("Writing to timed out socket didn't fail"
                           " as it should have: %s" % sys.exc_info()[1])
         else:
-            self.fail("Writing to timed out socket didn't fail"
-                      " as it should have: %s" %
-                      response.read())
+            if response.status != 408:
+                self.fail("Writing to timed out socket didn't fail"
+                          " as it should have: %s" %
+                          response.read())
         
         conn.close()
         
         # but timeout on the headers
         conn.send('GET /hello HTTP/1.1')
         # Wait for our socket timeout
-        time.sleep(timeout * 10)
+        time.sleep(timeout * 2)
         response = conn.response_class(conn.sock, method="GET")
         response.begin()
         self.assertEqual(response.status, 408)
     def test_598(self):
         remote_data_conn = urllib.urlopen('%s://%s:%s/one_megabyte_of_a/' %
                                           (self.scheme, self.HOST, self.PORT,))
-        received_data = remote_data_conn.read(512)
-        time.sleep(6.0)
-        remaining = 1024*1024 - 512
-        received_data = ' '
-        while remaining and received_data:
-            received_data = remote_data_conn.read(remaining)
-            remaining -= len(received_data)
+        buf = remote_data_conn.read(512)
+        time.sleep(timeout * 0.6)
+        remaining = (1024 * 1024) - 512
+        while remaining:
+            data = remote_data_conn.read(remaining)
+            if not data:
+                break
+            else:
+                buf += data
+            remaining -= len(data)
        
-        self.assertTrue(received_data)
+        self.assertEqual(len(buf), 1024 * 1024)
+        self.assertEqual(buf, "a" * 1024 * 1024)
         self.assertEqual(remaining, 0)
         remote_data_conn.close()
 
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.