diff options
author | Victor Stinner <vstinner@redhat.com> | 2015-07-24 22:03:00 +0200 |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2015-07-24 22:03:38 +0200 |
commit | ce41fba64d504647e3c2379094408acd16a38338 (patch) | |
tree | c2958c37dc9cf238562528a0c210cef76c3e993b | |
parent | 9bb67431adc916d9d4b4e23ca257658c980d035d (diff) | |
download | trollius-git-ce41fba64d504647e3c2379094408acd16a38338.tar.gz |
Fix ResourceWarning warnings in test_streams
-rw-r--r-- | tests/test_streams.py | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/tests/test_streams.py b/tests/test_streams.py index 242b377..ef6f603 100644 --- a/tests/test_streams.py +++ b/tests/test_streams.py @@ -446,6 +446,8 @@ class StreamReaderTests(test_utils.TestCase): def handle_client(self, client_reader, client_writer): data = yield from client_reader.readline() client_writer.write(data) + yield from client_writer.drain() + client_writer.close() def start(self): sock = socket.socket() @@ -457,12 +459,8 @@ class StreamReaderTests(test_utils.TestCase): return sock.getsockname() def handle_client_callback(self, client_reader, client_writer): - task = asyncio.Task(client_reader.readline(), loop=self.loop) - - def done(task): - client_writer.write(task.result()) - - task.add_done_callback(done) + self.loop.create_task(self.handle_client(client_reader, + client_writer)) def start_callback(self): sock = socket.socket() @@ -522,6 +520,8 @@ class StreamReaderTests(test_utils.TestCase): def handle_client(self, client_reader, client_writer): data = yield from client_reader.readline() client_writer.write(data) + yield from client_writer.drain() + client_writer.close() def start(self): self.server = self.loop.run_until_complete( @@ -530,18 +530,14 @@ class StreamReaderTests(test_utils.TestCase): loop=self.loop)) def handle_client_callback(self, client_reader, client_writer): - task = asyncio.Task(client_reader.readline(), loop=self.loop) - - def done(task): - client_writer.write(task.result()) - - task.add_done_callback(done) + self.loop.create_task(self.handle_client(client_reader, + client_writer)) def start_callback(self): - self.server = self.loop.run_until_complete( - asyncio.start_unix_server(self.handle_client_callback, - path=self.path, - loop=self.loop)) + start = asyncio.start_unix_server(self.handle_client_callback, + path=self.path, + loop=self.loop) + self.server = self.loop.run_until_complete(start) def stop(self): if self.server is not None: |