From: Ben Darnell Date: Wed, 1 May 2013 03:01:54 +0000 (-0400) Subject: Fix another case in which streaming read_until_close passed data to the final callback. X-Git-Tag: v3.1.0~89 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c633aa507218b1e2a5fce9b267785c8a38c4302c;p=thirdparty%2Ftornado.git Fix another case in which streaming read_until_close passed data to the final callback. Closes #774. --- diff --git a/tornado/iostream.py b/tornado/iostream.py index b84d17734..5b4a45f9c 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -234,6 +234,10 @@ class BaseIOStream(object): if any(exc_info): self.error = exc_info[1] if self._read_until_close: + if (self._streaming_callback is not None and + self._read_buffer_size): + self._run_callback(self._streaming_callback, + self._consume(self._read_buffer_size)) callback = self._read_callback self._read_callback = None self._read_until_close = False diff --git a/tornado/test/iostream_test.py b/tornado/test/iostream_test.py index 138282dc7..9972c843d 100644 --- a/tornado/test/iostream_test.py +++ b/tornado/test/iostream_test.py @@ -261,19 +261,24 @@ class TestIOStreamMixin(object): server, client = self.make_iostream_pair() try: chunks = [] + closed = [False] - def callback(data): + def streaming_callback(data): chunks.append(data) self.stop() - client.read_until_close(callback=callback, - streaming_callback=callback) + def close_callback(data): + assert not data, data + closed[0] = True + self.stop() + client.read_until_close(callback=close_callback, + streaming_callback=streaming_callback) server.write(b"1234") - self.wait() - server.write(b"5678") + self.wait(condition=lambda: len(chunks) == 1) + server.write(b"5678", self.stop) self.wait() server.close() - self.wait() - self.assertEqual(chunks, [b"1234", b"5678", b""]) + self.wait(condition=lambda: closed[0]) + self.assertEqual(chunks, [b"1234", b"5678"]) finally: server.close() client.close()