[Python-checkins] r79041 - in python/branches/py3k: Lib/test/test_asynchat.py

collin.winter python-checkins at python.org
Thu Mar 18 00:49:15 CET 2010


Author: collin.winter
Date: Thu Mar 18 00:49:15 2010
New Revision: 79041

Log:
Merged revisions 79038 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r79038 | collin.winter | 2010-03-17 15:36:26 -0700 (Wed, 17 Mar 2010) | 2 lines
  
  Fix a race condition in test_asynchat uncovered by the Unladen Swallow JIT.
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/test/test_asynchat.py

Modified: python/branches/py3k/Lib/test/test_asynchat.py
==============================================================================
--- python/branches/py3k/Lib/test/test_asynchat.py	(original)
+++ python/branches/py3k/Lib/test/test_asynchat.py	Thu Mar 18 00:49:15 2010
@@ -22,6 +22,9 @@
         self.event = event
         self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         self.port = support.bind_port(self.sock)
+        # This will be set if the client wants us to wait before echoing data
+        # back.
+        self.start_resend_event = None
 
     def run(self):
         self.sock.listen(1)
@@ -38,6 +41,9 @@
         # remove the SERVER_QUIT message
         self.buffer = self.buffer.replace(SERVER_QUIT, b'')
 
+        if self.start_resend_event:
+            self.start_resend_event.wait()
+
         # re-send entire set of collected data
         try:
             # this may fail on some tests, such as test_close_when_done, since
@@ -203,11 +209,18 @@
 
     def test_close_when_done(self):
         s, event = start_echo_server()
+        s.start_resend_event = threading.Event()
         c = echo_client(b'\n', s.port)
         c.push(b"hello world\nI'm not dead yet!\n")
         c.push(SERVER_QUIT)
         c.close_when_done()
         asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
+
+        # Only allow the server to start echoing data back to the client after
+        # the client has closed its connection.  This prevents a race condition
+        # where the server echoes all of its data before we can check that it
+        # got any down below.
+        s.start_resend_event.set()
         s.join()
 
         self.assertEqual(c.contents, [])


More information about the Python-checkins mailing list