From 7fa64b0166eae13e687640583d6c70cd7666217c Mon Sep 17 00:00:00 2001 From: Ophir LOJKINE Date: Tue, 13 Oct 2020 11:01:38 +0200 Subject: [PATCH] Add a regression test for large stderr reading Regression test for https://github.com/MagicStack/uvloop/issues/363 --- tests/test_process.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_process.py b/tests/test_process.py index 6122d76d..a9c7b91f 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -673,6 +673,34 @@ async def test_subprocess(): loop.run_until_complete(test_subprocess()) + def test_communicate_large_stdout_65536(self): + self._test_communicate_large_stdout(65536) + + def test_communicate_large_stdout_65537(self): + self._test_communicate_large_stdout(65537) + + def test_communicate_large_stdout_1000000(self): + self._test_communicate_large_stdout(1000000) + + def _test_communicate_large_stdout(self, size): + async def copy_stdin_to_stdout(stdin): + # See https://github.com/MagicStack/uvloop/issues/363 + # A program that copies stdin to stdout character by character + code = ('import sys, shutil; ' + 'shutil.copyfileobj(sys.stdin, sys.stdout, 1)') + proc = await asyncio.create_subprocess_exec( + sys.executable, b'-W', b'ignore', b'-c', code, + stdin=asyncio.subprocess.PIPE, + stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.PIPE) + stdout, _stderr = await asyncio.wait_for(proc.communicate(stdin), + 60.0) + return stdout + + stdin = b'x' * size + stdout = self.loop.run_until_complete(copy_stdin_to_stdout(stdin)) + self.assertEqual(stdout, stdin) + def test_write_huge_stdin_8192(self): self._test_write_huge_stdin(8192)