From: Ben Darnell Date: Sun, 18 Sep 2011 23:44:32 +0000 (-0700) Subject: Add a test for the bug fixed in commit e811959 X-Git-Tag: v2.1.0~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5cf9890b45c5357d14329d0f9a674b7aa2c531d9;p=thirdparty%2Ftornado.git Add a test for the bug fixed in commit e811959 --- diff --git a/tornado/test/iostream_test.py b/tornado/test/iostream_test.py index 3567c8024..dd3b8f6bb 100644 --- a/tornado/test/iostream_test.py +++ b/tornado/test/iostream_test.py @@ -137,3 +137,26 @@ class TestIOStream(AsyncHTTPTestCase, LogTrapTestCase): finally: server.close() client.close() + + def test_delayed_close_callback(self): + # The scenario: Server closes the connection while there is a pending + # read that can be served out of buffered data. The client does not + # run the close_callback as soon as it detects the close, but rather + # defers it until after the buffered read has finished. + server, client = self.make_iostream_pair() + try: + client.set_close_callback(self.stop) + server.write(b("12")) + chunks = [] + def callback1(data): + chunks.append(data) + client.read_bytes(1, callback2) + server.close() + def callback2(data): + chunks.append(data) + client.read_bytes(1, callback1) + self.wait() # stopped by close_callback + self.assertEqual(chunks, [b("1"), b("2")]) + finally: + server.close() + client.close()