示例#1
0

class TestPipeIOStream(AsyncTestCase):
    def test_pipe_iostream(self):
        r, w = os.pipe()

        rs = PipeIOStream(r, io_loop=self.io_loop)
        ws = PipeIOStream(w, io_loop=self.io_loop)

        ws.write(b("hel"))
        ws.write(b("lo world"))

        rs.read_until(b(' '), callback=self.stop)
        data = self.wait()
        self.assertEqual(data, b("hello "))

        rs.read_bytes(3, self.stop)
        data = self.wait()
        self.assertEqual(data, b("wor"))

        ws.close()

        rs.read_until_close(self.stop)
        data = self.wait()
        self.assertEqual(data, b("ld"))

        rs.close()


TestPipeIOStream = skipIfNonUnix(TestPipeIOStream)
示例#2
0
                    # Now kill them normally so they won't be restarted
                    fetch("/?exit=0", fail_ok=True)
                    # One process left; watch it's pid change
                    pid = int(fetch("/").body)
                    fetch("/?exit=4", fail_ok=True)
                    pid2 = int(fetch("/").body)
                    self.assertNotEqual(pid, pid2)

                    # Kill the last one so we shut down cleanly
                    fetch("/?exit=0", fail_ok=True)

                    os._exit(0)
            except Exception:
                logging.error("exception in child process %d", id, exc_info=True)
                raise
ProcessTest = skipIfNonUnix(ProcessTest)


class SubprocessTest(AsyncTestCase):
    def test_subprocess(self):
        subproc = Subprocess([sys.executable, '-u', '-i'],
                             stdin=Subprocess.STREAM,
                             stdout=Subprocess.STREAM, stderr=subprocess.STDOUT,
                             io_loop=self.io_loop)
        self.addCleanup(lambda: os.kill(subproc.pid, signal.SIGTERM))
        subproc.stdout.read_until(b('>>> '), self.stop)
        self.wait()
        subproc.stdin.write(b("print('hello')\n"))
        subproc.stdout.read_until(b('\n'), self.stop)
        data = self.wait()
        self.assertEqual(data, b("hello\n"))
示例#3
0
    def _make_client_iostream(self, connection, **kwargs):
        return SSLIOStream(connection, io_loop=self.io_loop, **kwargs)
TestIOStreamSSL = skipIfNoSSL(TestIOStreamSSL)

class TestPipeIOStream(AsyncTestCase):
    def test_pipe_iostream(self):
        r, w = os.pipe()

        rs = PipeIOStream(r, io_loop=self.io_loop)
        ws = PipeIOStream(w, io_loop=self.io_loop)

        ws.write(b("hel"))
        ws.write(b("lo world"))

        rs.read_until(b(' '), callback=self.stop)
        data = self.wait()
        self.assertEqual(data, b("hello "))

        rs.read_bytes(3, self.stop)
        data = self.wait()
        self.assertEqual(data, b("wor"))

        ws.close()

        rs.read_until_close(self.stop)
        data = self.wait()
        self.assertEqual(data, b("ld"))

        rs.close()
TestPipeIOStream = skipIfNonUnix(TestPipeIOStream)
示例#4
0
                    # Now kill them normally so they won't be restarted
                    fetch("/?exit=0", fail_ok=True)
                    # One process left; watch it's pid change
                    pid = int(fetch("/").body)
                    fetch("/?exit=4", fail_ok=True)
                    pid2 = int(fetch("/").body)
                    self.assertNotEqual(pid, pid2)

                    # Kill the last one so we shut down cleanly
                    fetch("/?exit=0", fail_ok=True)

                    os._exit(0)
            except Exception:
                logging.error("exception in child process %d", id, exc_info=True)
                raise
ProcessTest = skipIfNonUnix(ProcessTest)


class SubprocessTest(AsyncTestCase):
    def test_subprocess(self):
        subproc = Subprocess([sys.executable, '-u', '-i'],
                             stdin=Subprocess.STREAM,
                             stdout=Subprocess.STREAM, stderr=subprocess.STDOUT,
                             io_loop=self.io_loop)
        self.addCleanup(lambda: os.kill(subproc.pid, signal.SIGTERM))
        subproc.stdout.read_until(b('>>> '), self.stop)
        self.wait()
        subproc.stdin.write(b("print('hello')\n"))
        subproc.stdout.read_until(b('\n'), self.stop)
        data = self.wait()
        self.assertEqual(data, b("hello\n"))