[Zope3-checkins] SVN: Zope3/branches/mkerrin-twisted-upgrade/src/zope/app/twisted/tests/test_inputbuffering.py Make this test a bit more robust - if it incounters an error it should now fail with an

Michael Kerrin michael.kerrin at openapp.biz
Mon Nov 13 14:09:21 EST 2006


Log message for revision 71118:
  Make this test a bit more robust - if it incounters an error it should now fail with an
  error instead of hanging for a long time and then failing.
  

Changed:
  U   Zope3/branches/mkerrin-twisted-upgrade/src/zope/app/twisted/tests/test_inputbuffering.py

-=-
Modified: Zope3/branches/mkerrin-twisted-upgrade/src/zope/app/twisted/tests/test_inputbuffering.py
===================================================================
--- Zope3/branches/mkerrin-twisted-upgrade/src/zope/app/twisted/tests/test_inputbuffering.py	2006-11-13 13:57:40 UTC (rev 71117)
+++ Zope3/branches/mkerrin-twisted-upgrade/src/zope/app/twisted/tests/test_inputbuffering.py	2006-11-13 19:09:20 UTC (rev 71118)
@@ -17,6 +17,9 @@
 an application thread.
 
 Also, test that both small and (somewhat) large inputs are handled correctly.
+We do this by marking the requests are processed in the correct order. Namely that
+the 'good' request is processed before the 'bad' request. This is done by marking
+the requests with the HTTP header 'X-Thread-Identify'.
 
     >>> instance = Instance()
     >>> instance.start()
@@ -28,6 +31,7 @@
     >>> bad.connect(('localhost', instance.port))
     >>> bad.sendall('GET http://localhost:%s/echo HTTP/1.1\r\n'
     ...             % instance.port)
+    >>> bad.sendall('X-Thread-Identify: bad\r\n')
     >>> bad.sendall('Content-Length: 10\r\n')
     >>> bad.sendall('Content-Type: text/plain\r\n')
     >>> bad.sendall('\r\n')
@@ -41,6 +45,7 @@
     >>> s.connect(('localhost', instance.port))
     >>> s.sendall('GET http://localhost:%s/echo HTTP/1.1\r\n'
     ...           % instance.port)
+    >>> s.sendall('X-Thread-Identify: good\r\n')
     >>> s.sendall('Content-Length: 120005\r\n')
     >>> s.sendall('Content-Type: text/plain\r\n')
     >>> s.sendall('\r\n')
@@ -55,9 +60,18 @@
 
     >>> s.close()
 
+    >>> bad.sendall('end\r\n' + 'xxxxxxxxxx\r\n')
+    >>> f = bad.makefile()
 
-    >>> bad.sendall('end\r\n' + 'xxxxxxxxxx\n')
+If the requests were processed in the wrong order then the first line of the
+'bad' request will be 'HTTP/1.1 500 Internal Server Error\r\n'
+
+    >>> f.readline()
+    'HTTP/1.1 200 OK\r\n'
+
+    >>> f.close()
     >>> bad.close()
+
     >>> instance.stop()
     >>> shutil.rmtree(instance.dir)
 
@@ -78,6 +92,8 @@
 import ZEO.tests.testZEO # we really need another library
 import ZEO.tests.forker
 
+# This is a list of the ordering we expect to receive the requests in.
+received = ['good', 'bad']
 
 class Echo:
 
@@ -87,6 +103,16 @@
     def echo(self):
         s = 0
         result = []
+
+        rid = self.request.getHeader('X-Thread-Identify', None)
+        if rid is None:
+            raise ValueError("""All requests should be marked with
+                                the 'X-Thread-Identify' header""")
+
+        expectedrid = received.pop(0)
+        if expectedrid != rid:
+            raise ValueError("Requests received in the wrong order.")
+
         while 1:
             l = self.request.bodyStream.readline()
             s += len(l)
@@ -96,6 +122,7 @@
                 break
         return ''.join(result)
 
+
 class Instance:
 
     def __init__(self, dir=None, name=None, zeo_port=1):



More information about the Zope3-Checkins mailing list