From f98e135979a595cc7c41017ad3b5c1c8bdec058c Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Fri, 21 Sep 2018 13:04:55 -0400 Subject: [PATCH] Add a test that processes handle invalid FDs --- tests/test_process.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/test_process.py b/tests/test_process.py index f6e9ea1..34a0570 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -375,6 +375,40 @@ print("OK") self.assertEqual(num_fd_1, num_fd_2) + def test_subprocess_invalid_stdin(self): + fd = None + for tryfd in range(10000, 1000, -1): + try: + tryfd = os.dup(tryfd) + except OSError: + fd = tryfd + break + else: + os.close(tryfd) + else: + self.fail('could not find a free FD') + + async def main(): + with self.assertRaises(OSError): + await asyncio.create_subprocess_exec( + 'ls', + loop=self.loop, + stdin=fd) + + with self.assertRaises(OSError): + await asyncio.create_subprocess_exec( + 'ls', + loop=self.loop, + stdout=fd) + + with self.assertRaises(OSError): + await asyncio.create_subprocess_exec( + 'ls', + loop=self.loop, + stderr=fd) + + self.loop.run_until_complete(main()) + class _AsyncioTests: