|
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") |
@@ -879,6 +879,44 @@ async def main(): |
879 | 879 |
|
880 | 880 | self.loop.run_until_complete(main()) |
881 | 881 |
|
| 882 | + @warnings_helper.ignore_warnings(category=ResourceWarning) |
| 883 | + def test_subprocess_read_pipe_cancelled(self): |
| 884 | + async def main(): |
| 885 | + loop = asyncio.get_running_loop() |
| 886 | + loop.connect_read_pipe = mock.AsyncMock(side_effect=asyncio.CancelledError) |
| 887 | + with self.assertRaises(asyncio.CancelledError): |
| 888 | + await asyncio.create_subprocess_exec(*PROGRAM_BLOCKED, stderr=asyncio.subprocess.PIPE) |
| 889 | + |
| 890 | + asyncio.run(main()) |
| 891 | + gc_collect() |
| 892 | + |
| 893 | + @warnings_helper.ignore_warnings(category=ResourceWarning) |
| 894 | + def test_subprocess_write_pipe_cancelled(self): |
| 895 | + async def main(): |
| 896 | + loop = asyncio.get_running_loop() |
| 897 | + loop.connect_write_pipe = mock.AsyncMock(side_effect=asyncio.CancelledError) |
| 898 | + with self.assertRaises(asyncio.CancelledError): |
| 899 | + await asyncio.create_subprocess_exec(*PROGRAM_BLOCKED, stdin=asyncio.subprocess.PIPE) |
| 900 | + |
| 901 | + asyncio.run(main()) |
| 902 | + gc_collect() |
| 903 | + |
| 904 | + @warnings_helper.ignore_warnings(category=ResourceWarning) |
| 905 | + def test_subprocess_read_write_pipe_cancelled(self): |
| 906 | + async def main(): |
| 907 | + loop = asyncio.get_running_loop() |
| 908 | + loop.connect_read_pipe = mock.AsyncMock(side_effect=asyncio.CancelledError) |
| 909 | + loop.connect_write_pipe = mock.AsyncMock(side_effect=asyncio.CancelledError) |
| 910 | + with self.assertRaises(asyncio.CancelledError): |
| 911 | + await asyncio.create_subprocess_exec( |
| 912 | + *PROGRAM_BLOCKED, |
| 913 | + stdin=asyncio.subprocess.PIPE, |
| 914 | + stdout=asyncio.subprocess.PIPE, |
| 915 | + stderr=asyncio.subprocess.PIPE, |
| 916 | + ) |
| 917 | + |
| 918 | + asyncio.run(main()) |
| 919 | + gc_collect() |
882 | 920 |
|
883 | 921 | if sys.platform != 'win32': |
884 | 922 | # Unix |
|
0 commit comments