Skip to content

Commit 707fd4c

Browse files
committed
Add failing unit tests to reproduce issue #312
1 parent 35f8250 commit 707fd4c

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
def suite():
88
test_loader = unittest.TestLoader()
99
test_suite = test_loader.discover(
10-
os.path.dirname(__file__), pattern='test_*.py')
10+
os.path.dirname(__file__), pattern='test_pr*.py')
1111
return test_suite
1212

1313

tests/test_process.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,59 @@ 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+
# this one only fails on darwin...
667+
if sys.platform == 'darwin':
668+
unittest.expectedFailure(test_write_huge_stdin_8193)
669+
670+
def test_write_huge_stdin_219263(self):
671+
self._test_write_huge_stdin(219263)
672+
# this one only fails on darwin, but not on linux
673+
if sys.platform == 'darwin':
674+
unittest.expectedFailure(test_write_huge_stdin_219263)
675+
676+
# this one fails on darwin and linux...
677+
@unittest.expectedFailure
678+
def test_write_huge_stdin_219264(self):
679+
self._test_write_huge_stdin(219264)
680+
681+
def _test_write_huge_stdin(self, buf_size):
682+
code = '''
683+
import sys
684+
n = 0
685+
while True:
686+
line = sys.stdin.readline()
687+
if not line:
688+
print("unexpected EOF", file=sys.stderr)
689+
break
690+
if line == "END\\n":
691+
break
692+
n+=1
693+
print(n)'''
694+
num_lines = buf_size - len(b"END\n")
695+
args = [sys.executable, b'-W', b'ignore', b'-c', code]
696+
async def test():
697+
proc = await asyncio.create_subprocess_exec(*args,
698+
stdout=asyncio.subprocess.PIPE,
699+
stdin=asyncio.subprocess.PIPE)
700+
data = b"\n" * num_lines + b"END\n"
701+
self.assertEqual(len(data), buf_size)
702+
proc.stdin.write(data)
703+
await proc.stdin.drain()
704+
try:
705+
await asyncio.wait_for(proc.wait(), timeout=1.0)
706+
except asyncio.TimeoutError:
707+
proc.kill()
708+
proc.stdin.close()
709+
await proc.wait()
710+
raise
711+
out = await proc.stdout.read()
712+
self.assertEqual(int(out), num_lines)
713+
self.loop.run_until_complete(test())
661714

662715
class Test_UV_Process(_TestProcess, tb.UVTestCase):
663716

@@ -797,3 +850,5 @@ def test_process_delayed_stdio__not_paused__no_stdin(self):
797850
('STDOUT', 'LOST'),
798851
('CL', 0, None)
799852
})
853+
if __name__ == "__main__":
854+
unittest.main()

0 commit comments

Comments
 (0)