From: Ben Darnell Date: Fri, 27 Mar 2015 03:50:15 +0000 (-0400) Subject: Fix read_until_close's Future return with streaming_callback. X-Git-Tag: v4.2.0b1~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4dd78cffa1ad9a40a8feb9a7d3276d025c5c5d53;p=thirdparty%2Ftornado.git Fix read_until_close's Future return with streaming_callback. Fixes #1395. --- diff --git a/tornado/iostream.py b/tornado/iostream.py index 65e7b1714..a0f1eee41 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -669,13 +669,13 @@ class BaseIOStream(object): else: callback = self._read_callback self._read_callback = self._streaming_callback = None - if self._read_future is not None: - assert callback is None - future = self._read_future - self._read_future = None - future.set_result(self._consume(size)) + if self._read_future is not None: + assert callback is None + future = self._read_future + self._read_future = None + future.set_result(self._consume(size)) if callback is not None: - assert self._read_future is None + assert (self._read_future is None) or streaming self._run_callback(callback, self._consume(size)) else: # If we scheduled a callback, we will add the error listener diff --git a/tornado/test/iostream_test.py b/tornado/test/iostream_test.py index 7c57324d3..21b49c53f 100644 --- a/tornado/test/iostream_test.py +++ b/tornado/test/iostream_test.py @@ -328,6 +328,31 @@ class TestIOStreamMixin(object): server.close() client.close() + def test_streaming_until_close_future(self): + server, client = self.make_iostream_pair() + try: + chunks = [] + + @gen.coroutine + def client_task(): + yield client.read_until_close(streaming_callback=chunks.append) + + @gen.coroutine + def server_task(): + yield server.write(b"1234") + yield gen.moment + yield server.write(b"5678") + server.close() + + @gen.coroutine + def f(): + yield [client_task(), server_task()] + self.io_loop.run_sync(f) + self.assertEqual(chunks, [b"1234", b"5678"]) + 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