Ejemplo n.º 1
0
 def testReturncode(self, cmd1, cmd2, returncode):
     p1 = v2v._simple_exec_cmd([cmd1], stdout=subprocess.PIPE)
     p2 = v2v._simple_exec_cmd([cmd2],
                               stdin=p1.stdout,
                               stdout=subprocess.PIPE)
     p = v2v.PipelineProc(p1, p2)
     p.wait(self.PROC_WAIT_TIMEOUT)
     self.assertEqual(p.returncode, returncode)
Ejemplo n.º 2
0
 def testReturncode(self, cmd1, cmd2, returncode):
     p1 = v2v._simple_exec_cmd([cmd1],
                               stdout=subprocess.PIPE)
     p2 = v2v._simple_exec_cmd([cmd2],
                               stdin=p1.stdout,
                               stdout=subprocess.PIPE)
     p = v2v.PipelineProc(p1, p2)
     p.wait(self.PROC_WAIT_TIMEOUT)
     self.assertEqual(p.returncode, returncode)
Ejemplo n.º 3
0
 def testWait(self, cmd1, cmd2, waitRet):
     p1 = v2v._simple_exec_cmd(cmd1, stdout=subprocess.PIPE)
     p2 = v2v._simple_exec_cmd(cmd2,
                               stdin=p1.stdout,
                               stdout=subprocess.PIPE)
     p = v2v.PipelineProc(p1, p2)
     ret = p.wait(2)
     p.kill()
     self.assertEqual(ret, waitRet)
Ejemplo n.º 4
0
 def testWait(self, cmd1, cmd2, waitRet):
     p1 = v2v._simple_exec_cmd(cmd1,
                               stdout=subprocess.PIPE)
     p2 = v2v._simple_exec_cmd(cmd2,
                               stdin=p1.stdout,
                               stdout=subprocess.PIPE)
     p = v2v.PipelineProc(p1, p2)
     ret = p.wait(2)
     p.kill()
     self.assertEqual(ret, waitRet)
Ejemplo n.º 5
0
 def testReturncode(self, cmd1, cmd2, returncode):
     p1 = v2v._simple_exec_cmd([cmd1], stdout=subprocess.PIPE)
     with terminating(p1):
         p2 = v2v._simple_exec_cmd([cmd2],
                                   stdin=p1.stdout,
                                   stdout=subprocess.PIPE)
         with terminating(p2):
             p = v2v.PipelineProc(p1, p2)
             p.wait(self.PROC_WAIT_TIMEOUT)
             assert p.returncode == returncode
Ejemplo n.º 6
0
 def testWait(self, cmd1, cmd2):
     p1 = v2v._simple_exec_cmd(cmd1, stdout=subprocess.PIPE)
     with terminating(p1):
         p2 = v2v._simple_exec_cmd(cmd2,
                                   stdin=p1.stdout,
                                   stdout=subprocess.PIPE)
         with terminating(p2):
             p = v2v.PipelineProc(p1, p2)
             ret = p.wait(2 * SHORT_SLEEP)
             p.kill()
             assert ret is False
Ejemplo n.º 7
0
 def testWait(self, cmd1, cmd2):
     p1 = v2v._simple_exec_cmd(cmd1,
                               stdout=subprocess.PIPE)
     with terminating(p1):
         p2 = v2v._simple_exec_cmd(cmd2,
                                   stdin=p1.stdout,
                                   stdout=subprocess.PIPE)
         with terminating(p2):
             p = v2v.PipelineProc(p1, p2)
             ret = p.wait(2 * SHORT_SLEEP)
             p.kill()
             self.assertEqual(ret, False)
Ejemplo n.º 8
0
 def test_wait_on_two_processes_that_finished(self):
     cmd = ['sleep', str(SHORT_SLEEP)]
     p1 = v2v._simple_exec_cmd(cmd, stdout=subprocess.PIPE)
     with terminating(p1):
         p2 = v2v._simple_exec_cmd(
             cmd, stdin=p1.stdout, stdout=subprocess.PIPE)
         with terminating(p2):
             # Wait for the processes to finish.
             time.sleep(2 * SHORT_SLEEP)
             p = v2v.PipelineProc(p1, p2)
             ret = p.wait(2 * SHORT_SLEEP)
             p.kill()
             self.assertEqual(ret, True)
Ejemplo n.º 9
0
 def test_wait_on_two_processes_that_finish_before_timeout(self):
     cmd1 = ['sleep', str(SHORT_SLEEP)]
     cmd2 = ['sleep', str(1.5 * SHORT_SLEEP)]
     p1 = v2v._simple_exec_cmd(cmd1, stdout=subprocess.PIPE)
     with terminating(p1):
         p2 = v2v._simple_exec_cmd(
             cmd2, stdin=p1.stdout, stdout=subprocess.PIPE)
         with terminating(p2):
             p = v2v.PipelineProc(p1, p2)
             # Processes finish at different times but before the timeout.
             ret = p.wait(3 * SHORT_SLEEP)
             p.kill()
             self.assertEqual(ret, True)
Ejemplo n.º 10
0
 def test_wait_on_two_processes_that_finished(self):
     cmd = ['sleep', str(SHORT_SLEEP)]
     p1 = v2v._simple_exec_cmd(cmd, stdout=subprocess.PIPE)
     with terminating(p1):
         p2 = v2v._simple_exec_cmd(
             cmd, stdin=p1.stdout, stdout=subprocess.PIPE)
         with terminating(p2):
             # Wait for the processes to finish.
             time.sleep(2 * SHORT_SLEEP)
             p = v2v.PipelineProc(p1, p2)
             ret = p.wait(2 * SHORT_SLEEP)
             p.kill()
             self.assertEqual(ret, True)
Ejemplo n.º 11
0
 def test_wait_on_two_processes_that_finish_before_timeout(self):
     cmd1 = ['sleep', str(SHORT_SLEEP)]
     cmd2 = ['sleep', str(1.5 * SHORT_SLEEP)]
     p1 = v2v._simple_exec_cmd(cmd1, stdout=subprocess.PIPE)
     with terminating(p1):
         p2 = v2v._simple_exec_cmd(
             cmd2, stdin=p1.stdout, stdout=subprocess.PIPE)
         with terminating(p2):
             p = v2v.PipelineProc(p1, p2)
             # Processes finish at different times but before the timeout.
             ret = p.wait(3 * SHORT_SLEEP)
             p.kill()
             self.assertEqual(ret, True)
Ejemplo n.º 12
0
    def testRun(self):
        msg = 'foo\nbar'
        p1 = v2v._simple_exec_cmd(['echo', '-n', msg], stdout=subprocess.PIPE)
        p2 = v2v._simple_exec_cmd(['cat'],
                                  stdin=p1.stdout,
                                  stdout=subprocess.PIPE)

        p = v2v.PipelineProc(p1, p2)
        self.assertEqual(p.pids, [p1.pid, p2.pid])

        ret = p.wait(self.PROC_WAIT_TIMEOUT)
        self.assertEqual(ret, True)

        out = p.stdout.read()
        self.assertEqual(out, msg)
Ejemplo n.º 13
0
    def testWait(self, cmd1, cmd2, waitRet):
        if six.PY3 and waitRet:
            raise SkipTest('broken on Python 3')

        p1 = v2v._simple_exec_cmd(cmd1,
                                  stdout=subprocess.PIPE)
        with terminating(p1):
            p2 = v2v._simple_exec_cmd(cmd2,
                                      stdin=p1.stdout,
                                      stdout=subprocess.PIPE)
            with terminating(p2):
                p = v2v.PipelineProc(p1, p2)
                ret = p.wait(2 * SHORT_SLEEP)
                p.kill()
                self.assertEqual(ret, waitRet)
Ejemplo n.º 14
0
    def testRun(self):
        msg = 'foo\nbar'
        p1 = v2v._simple_exec_cmd(['echo', '-n', msg],
                                  stdout=subprocess.PIPE)
        p2 = v2v._simple_exec_cmd(['cat'],
                                  stdin=p1.stdout,
                                  stdout=subprocess.PIPE)

        p = v2v.PipelineProc(p1, p2)
        self.assertEqual(p.pids, [p1.pid, p2.pid])

        ret = p.wait(self.PROC_WAIT_TIMEOUT)
        self.assertEqual(ret, True)

        out = p.stdout.read()
        self.assertEqual(out, msg)
Ejemplo n.º 15
0
    def testRun(self):
        msg = 'foo\nbar'
        p1 = v2v._simple_exec_cmd(['echo', '-n', msg], stdout=subprocess.PIPE)
        with terminating(p1):
            p2 = v2v._simple_exec_cmd(['cat'],
                                      stdin=p1.stdout,
                                      stdout=subprocess.PIPE)
            with terminating(p2):
                p = v2v.PipelineProc(p1, p2)
                assert p.pids == [p1.pid, p2.pid]

                ret = p.wait(self.PROC_WAIT_TIMEOUT)
                assert ret is True

                out = p.stdout.read()
                assert out == msg.encode()
Ejemplo n.º 16
0
    def testSimpleExecCmd(self):
        p = v2v._simple_exec_cmd(['cat'],
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE)
        msg = "test\ntest"
        p.stdin.write(msg.encode())
        p.stdin.close()
        p.wait()
        out = p.stdout.read()
        self.assertEqual(out, msg.encode())

        p = v2v._simple_exec_cmd(['/bin/sh', '-c', 'echo -en "%s" >&2' % msg],
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)
        p.wait()
        out = p.stdout.read()
        self.assertEqual(out, msg.encode())
Ejemplo n.º 17
0
    def testSimpleExecCmd(self):
        p = v2v._simple_exec_cmd(['cat'],
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE)
        msg = "test\ntest"
        p.stdin.write(msg.encode())
        p.stdin.close()
        p.wait()
        out = p.stdout.read()
        self.assertEqual(out, msg.encode())

        p = v2v._simple_exec_cmd(['/bin/sh', '-c', 'echo -en "%s" >&2' % msg],
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)
        p.wait()
        out = p.stdout.read()
        self.assertEqual(out, msg.encode())