Skip to content

Commit 90b9e7f

Browse files
tardypfantix
authored andcommitted
Add failing unit tests to reproduce issue MagicStack#312
* closes MagicStack#313
1 parent ede1fb2 commit 90b9e7f

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/test_process.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,55 @@ async def test_subprocess():
658658

659659
loop.run_until_complete(test_subprocess())
660660

661+
def test_write_huge_stdin_8192(self):
662+
self._test_write_huge_stdin(8192)
663+
664+
def test_write_huge_stdin_8193(self):
665+
self._test_write_huge_stdin(8193)
666+
667+
def test_write_huge_stdin_219263(self):
668+
self._test_write_huge_stdin(219263)
669+
670+
def test_write_huge_stdin_219264(self):
671+
self._test_write_huge_stdin(219264)
672+
673+
def _test_write_huge_stdin(self, buf_size):
674+
code = '''
675+
import sys
676+
n = 0
677+
while True:
678+
line = sys.stdin.readline()
679+
if not line:
680+
print("unexpected EOF", file=sys.stderr)
681+
break
682+
if line == "END\\n":
683+
break
684+
n+=1
685+
print(n)'''
686+
num_lines = buf_size - len(b"END\n")
687+
args = [sys.executable, b'-W', b'ignore', b'-c', code]
688+
689+
async def test():
690+
proc = await asyncio.create_subprocess_exec(
691+
*args,
692+
stdout=asyncio.subprocess.PIPE,
693+
stdin=asyncio.subprocess.PIPE)
694+
data = b"\n" * num_lines + b"END\n"
695+
self.assertEqual(len(data), buf_size)
696+
proc.stdin.write(data)
697+
await asyncio.wait_for(proc.stdin.drain(), timeout=1.0)
698+
try:
699+
await asyncio.wait_for(proc.wait(), timeout=1.0)
700+
except asyncio.TimeoutError:
701+
proc.kill()
702+
proc.stdin.close()
703+
await proc.wait()
704+
raise
705+
out = await proc.stdout.read()
706+
self.assertEqual(int(out), num_lines)
707+
708+
self.loop.run_until_complete(test())
709+
661710

662711
class Test_UV_Process(_TestProcess, tb.UVTestCase):
663712

0 commit comments

Comments
 (0)