Пример #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)
Пример #2
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)
Пример #3
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
Пример #4
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
Пример #5
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)
Пример #6
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)
Пример #7
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)
Пример #8
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)
Пример #9
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()