Skip to content

Commit 68db1a2

Browse files
lovasoafantix
authored andcommitted
Add a regression test for large stderr reading
Regression test for #363
1 parent fcb3735 commit 68db1a2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/test_process.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,34 @@ async def test_subprocess():
673673

674674
loop.run_until_complete(test_subprocess())
675675

676+
def test_communicate_large_stdout_65536(self):
677+
self._test_communicate_large_stdout(65536)
678+
679+
def test_communicate_large_stdout_65537(self):
680+
self._test_communicate_large_stdout(65537)
681+
682+
def test_communicate_large_stdout_1000000(self):
683+
self._test_communicate_large_stdout(1000000)
684+
685+
def _test_communicate_large_stdout(self, size):
686+
async def copy_stdin_to_stdout(stdin):
687+
# See https://github.com/MagicStack/uvloop/issues/363
688+
# A program that copies stdin to stdout character by character
689+
code = ('import sys, shutil; '
690+
'shutil.copyfileobj(sys.stdin, sys.stdout, 1)')
691+
proc = await asyncio.create_subprocess_exec(
692+
sys.executable, b'-W', b'ignore', b'-c', code,
693+
stdin=asyncio.subprocess.PIPE,
694+
stdout=asyncio.subprocess.PIPE,
695+
stderr=asyncio.subprocess.PIPE)
696+
stdout, _stderr = await asyncio.wait_for(proc.communicate(stdin),
697+
60.0)
698+
return stdout
699+
700+
stdin = b'x' * size
701+
stdout = self.loop.run_until_complete(copy_stdin_to_stdout(stdin))
702+
self.assertEqual(stdout, stdin)
703+
676704
def test_write_huge_stdin_8192(self):
677705
self._test_write_huge_stdin(8192)
678706

0 commit comments

Comments
 (0)