|
11 | 11 | from asyncio import subprocess |
12 | 12 | from test.test_asyncio import utils as test_utils |
13 | 13 | from test import support |
14 | | -from test.support import os_helper |
| 14 | +from test.support import os_helper, warnings_helper, gc_collect |
15 | 15 |
|
16 | 16 | if not support.has_subprocess_support: |
17 | 17 | raise unittest.SkipTest("test module requires subprocess") |
@@ -888,6 +888,44 @@ async def main(): |
888 | 888 |
|
889 | 889 | self.loop.run_until_complete(main()) |
890 | 890 |
|
| 891 | + @warnings_helper.ignore_warnings(category=ResourceWarning) |
| 892 | + def test_subprocess_read_pipe_cancelled(self): |
| 893 | + async def main(): |
| 894 | + loop = asyncio.get_running_loop() |
| 895 | + loop.connect_read_pipe = mock.AsyncMock(side_effect=asyncio.CancelledError) |
| 896 | + with self.assertRaises(asyncio.CancelledError): |
| 897 | + await asyncio.create_subprocess_exec(*PROGRAM_BLOCKED, stderr=asyncio.subprocess.PIPE) |
| 898 | + |
| 899 | + asyncio.run(main()) |
| 900 | + gc_collect() |
| 901 | + |
| 902 | + @warnings_helper.ignore_warnings(category=ResourceWarning) |
| 903 | + def test_subprocess_write_pipe_cancelled(self): |
| 904 | + async def main(): |
| 905 | + loop = asyncio.get_running_loop() |
| 906 | + loop.connect_write_pipe = mock.AsyncMock(side_effect=asyncio.CancelledError) |
| 907 | + with self.assertRaises(asyncio.CancelledError): |
| 908 | + await asyncio.create_subprocess_exec(*PROGRAM_BLOCKED, stdin=asyncio.subprocess.PIPE) |
| 909 | + |
| 910 | + asyncio.run(main()) |
| 911 | + gc_collect() |
| 912 | + |
| 913 | + @warnings_helper.ignore_warnings(category=ResourceWarning) |
| 914 | + def test_subprocess_read_write_pipe_cancelled(self): |
| 915 | + async def main(): |
| 916 | + loop = asyncio.get_running_loop() |
| 917 | + loop.connect_read_pipe = mock.AsyncMock(side_effect=asyncio.CancelledError) |
| 918 | + loop.connect_write_pipe = mock.AsyncMock(side_effect=asyncio.CancelledError) |
| 919 | + with self.assertRaises(asyncio.CancelledError): |
| 920 | + await asyncio.create_subprocess_exec( |
| 921 | + *PROGRAM_BLOCKED, |
| 922 | + stdin=asyncio.subprocess.PIPE, |
| 923 | + stdout=asyncio.subprocess.PIPE, |
| 924 | + stderr=asyncio.subprocess.PIPE, |
| 925 | + ) |
| 926 | + |
| 927 | + asyncio.run(main()) |
| 928 | + gc_collect() |
891 | 929 |
|
892 | 930 | if sys.platform != 'win32': |
893 | 931 | # Unix |
|
0 commit comments