summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asynchat.py
diff options
context:
space:
mode:
authorCollin Winter <collinw@gmail.com>2010-03-17 22:36:26 (GMT)
committerCollin Winter <collinw@gmail.com>2010-03-17 22:36:26 (GMT)
commit2227251a4e6a95984589e2af2d08ec4f18c9528d (patch)
tree44b9611fda46a3fa29ee6604d1f689bd4a58ab18 /Lib/test/test_asynchat.py
parent0dee9c1b5cba45c2a6c0320021f88397c559312e (diff)
downloadcpython-2227251a4e6a95984589e2af2d08ec4f18c9528d.zip
cpython-2227251a4e6a95984589e2af2d08ec4f18c9528d.tar.gz
cpython-2227251a4e6a95984589e2af2d08ec4f18c9528d.tar.bz2
Fix a race condition in test_asynchat uncovered by the Unladen Swallow JIT.
Diffstat (limited to 'Lib/test/test_asynchat.py')
-rw-r--r--Lib/test/test_asynchat.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_asynchat.py b/Lib/test/test_asynchat.py
index caa1117..af1d5c6 100644
--- a/Lib/test/test_asynchat.py
+++ b/Lib/test/test_asynchat.py
@@ -21,6 +21,9 @@ class echo_server(threading.Thread):
self.event = event
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.port = test_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)
@@ -37,6 +40,9 @@ class echo_server(threading.Thread):
# remove the SERVER_QUIT message
self.buffer = self.buffer.replace(SERVER_QUIT, '')
+ 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
@@ -202,11 +208,18 @@ class TestAsynchat(unittest.TestCase):
def test_close_when_done(self):
s, event = start_echo_server()
+ s.start_resend_event = threading.Event()
c = echo_client('\n', s.port)
c.push("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, [])