summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-07-17 10:48:33 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-07-17 10:48:33 (GMT)
commit0d35741b167b6c7fdd201944c0e57379b1f246fd (patch)
tree5aa00cc3059a2ae98498960b791f4be9eb58cb75 /Lib/test
parent68f411670ec2145e783ea657c9d54a0a14815048 (diff)
parentcc996b57890a251cef83101d5cfcbc58179cba5f (diff)
downloadcpython-0d35741b167b6c7fdd201944c0e57379b1f246fd.zip
cpython-0d35741b167b6c7fdd201944c0e57379b1f246fd.tar.gz
cpython-0d35741b167b6c7fdd201944c0e57379b1f246fd.tar.bz2
(Merge 3.4) asyncio, tulip issue 190: Process.communicate() must ignore
BrokenPipeError If you want to handle the BrokenPipeError, you can easily reimplement communicate(). Add also a unit test to ensure that stdin.write() + stdin.drain() raises BrokenPipeError.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_asyncio/test_subprocess.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index 3204d42..e41cabe 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -11,9 +11,6 @@ if sys.platform != 'win32':
# Program blocking
PROGRAM_BLOCKED = [sys.executable, '-c', 'import time; time.sleep(3600)']
-# Program sleeping during 1 second
-PROGRAM_SLEEP_1SEC = [sys.executable, '-c', 'import time; time.sleep(1)']
-
# Program copying input to output
PROGRAM_CAT = [
sys.executable, '-c',
@@ -118,16 +115,32 @@ class SubprocessMixin:
returncode = self.loop.run_until_complete(proc.wait())
self.assertEqual(-signal.SIGHUP, returncode)
- def test_broken_pipe(self):
+ def prepare_broken_pipe_test(self):
+ # buffer large enough to feed the whole pipe buffer
large_data = b'x' * support.PIPE_MAX_SIZE
+ # the program ends before the stdin can be feeded
create = asyncio.create_subprocess_exec(
- *PROGRAM_SLEEP_1SEC,
+ sys.executable, '-c', 'pass',
stdin=subprocess.PIPE,
loop=self.loop)
proc = self.loop.run_until_complete(create)
- with self.assertRaises(BrokenPipeError):
- self.loop.run_until_complete(proc.communicate(large_data))
+ return (proc, large_data)
+
+ def test_stdin_broken_pipe(self):
+ proc, large_data = self.prepare_broken_pipe_test()
+
+ # drain() must raise BrokenPipeError
+ proc.stdin.write(large_data)
+ self.assertRaises(BrokenPipeError,
+ self.loop.run_until_complete, proc.stdin.drain())
+ self.loop.run_until_complete(proc.wait())
+
+ def test_communicate_ignore_broken_pipe(self):
+ proc, large_data = self.prepare_broken_pipe_test()
+
+ # communicate() must ignore BrokenPipeError when feeding stdin
+ self.loop.run_until_complete(proc.communicate(large_data))
self.loop.run_until_complete(proc.wait())