Skip to content

Commit f98e135

Browse files
committed
Add a test that processes handle invalid FDs
1 parent 9cba749 commit f98e135

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/test_process.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,40 @@ async def main(n):
375375

376376
self.assertEqual(num_fd_1, num_fd_2)
377377

378+
def test_subprocess_invalid_stdin(self):
379+
fd = None
380+
for tryfd in range(10000, 1000, -1):
381+
try:
382+
tryfd = os.dup(tryfd)
383+
except OSError:
384+
fd = tryfd
385+
break
386+
else:
387+
os.close(tryfd)
388+
else:
389+
self.fail('could not find a free FD')
390+
391+
async def main():
392+
with self.assertRaises(OSError):
393+
await asyncio.create_subprocess_exec(
394+
'ls',
395+
loop=self.loop,
396+
stdin=fd)
397+
398+
with self.assertRaises(OSError):
399+
await asyncio.create_subprocess_exec(
400+
'ls',
401+
loop=self.loop,
402+
stdout=fd)
403+
404+
with self.assertRaises(OSError):
405+
await asyncio.create_subprocess_exec(
406+
'ls',
407+
loop=self.loop,
408+
stderr=fd)
409+
410+
self.loop.run_until_complete(main())
411+
378412

379413
class _AsyncioTests:
380414

0 commit comments

Comments
 (0)