From bde177837379d0828eb4c6f69b727cdc69a53692 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 29 Mar 2018 23:36:50 +0545 Subject: [PATCH] tests: merge tty_create_child() test into parent_test and fix hang --- tests/parent_test.py | 24 +++++++++++++++++++++++- tests/tty_create_child_test.py | 33 --------------------------------- 2 files changed, 23 insertions(+), 34 deletions(-) delete mode 100644 tests/tty_create_child_test.py diff --git a/tests/parent_test.py b/tests/parent_test.py index 169d237b..5473b015 100644 --- a/tests/parent_test.py +++ b/tests/parent_test.py @@ -1,11 +1,12 @@ import os import subprocess +import tempfile import time import unittest2 +import testlib import mitogen.parent -import testlib class ContextTest(testlib.RouterMixin, unittest2.TestCase): @@ -16,6 +17,27 @@ class ContextTest(testlib.RouterMixin, unittest2.TestCase): self.assertRaises(OSError, lambda: os.kill(pid, 0)) +class TtyCreateChildTest(unittest2.TestCase): + func = staticmethod(mitogen.parent.tty_create_child) + + def test_dev_tty_open_succeeds(self): + tf = tempfile.NamedTemporaryFile() + try: + pid, fd = self.func( + 'bash', '-c', 'exec 2>%s; echo hi > /dev/tty' % (tf.name,) + ) + deadline = time.time() + 5.0 + for line in mitogen.parent.iter_read(fd, deadline): + self.assertEquals('hi\n', line) + break + waited_pid, status = os.waitpid(pid, 0) + self.assertEquals(pid, waited_pid) + self.assertEquals(0, status) + self.assertEquals('', tf.read()) + finally: + tf.close() + + class IterReadTest(unittest2.TestCase): func = staticmethod(mitogen.parent.iter_read) diff --git a/tests/tty_create_child_test.py b/tests/tty_create_child_test.py deleted file mode 100644 index 879373ca..00000000 --- a/tests/tty_create_child_test.py +++ /dev/null @@ -1,33 +0,0 @@ - -import os -import tempfile -import time -import unittest2 - -import testlib -import mitogen.parent - - -class TtyCreateChildTest(unittest2.TestCase): - func = staticmethod(mitogen.parent.tty_create_child) - - def test_dev_tty_open_succeeds(self): - tf = tempfile.NamedTemporaryFile() - try: - pid, fd = self.func( - 'bash', '-c', 'exec 2>%s; echo hi > /dev/tty' % (tf.name,) - ) - # TODO: this waitpid hangs on OS X. Installing a SIGCHLD handler - # reveals the parent /is/ notified of the child's death, but - # calling waitpid() from within SIGCHLD yields "No such processes". - # Meanwhile, even inserting a sleep, the following call will hang. - waited_pid, status = os.waitpid(pid, 0) - self.assertEquals(pid, waited_pid) - self.assertEquals(0, status) - self.assertEquals('', tf.read()) - finally: - tf.close() - - -if __name__ == '__main__': - unittest2.main()