Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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
Exemple #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
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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()
Exemple #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())
Exemple #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())