示例#1
0
    def testTimeoutingSubSubProcesses(self):
        cmd = command.Command('echo "sleep 3;exit 5"|bash', 0.1, 1000)

        # There should be a timeout
        self.failUnlessRaises(command.SoftTimeoutException,
                              cmd.execute_in_shell)

        # If command is killed properly it should not return 5:
        self.assertNotEquals(cmd.return_value, 5)

        # If sub process was killed properly, execution time should be much
        # less than 3 seconds.
        self.assert_(cmd.execution_time < 2.5)
示例#2
0
 def testHardTimeout(self):
     cmd = command.Command("sleep 5", 100, 0.5)
     self.failUnlessRaises(command.HardTimeoutException,
                           cmd.execute_in_shell)
示例#3
0
 def testGetExecutionTime(self):
     cmd = command.Command("sleep 0.5")
     cmd.execute_in_shell()
     self.assertAlmostEquals(cmd.execution_time, 0.5, 1)
示例#4
0
 def testGetReturnValue(self):
     cmd = command.Command("echo 0", DUMMY_TIMEOUT_VALUE)
     self.assertEquals(cmd.return_value, None)
     cmd.execute_in_shell()
     self.assertEquals(cmd.return_value, 0)
示例#5
0
 def testGetStdout(self):
     cmd = command.Command("echo jee", DUMMY_TIMEOUT_VALUE)
     cmd.execute_in_shell()
     self._assertStdout(cmd, "jee\n")
示例#6
0
 def testGetStderr(self):
     cmd = command.Command("echo jee >&2", DUMMY_TIMEOUT_VALUE)
     cmd.execute_in_shell()
     self.assertEquals(cmd.stderr, "jee\n")
示例#7
0
 def testWrappedCommandWithEmptyWrapper(self):
     wrapper = ""
     cmd = "command"
     cmd_object = command.Command(cmd, wrapper=wrapper)
     expected = 'command'
     self.assertEquals(cmd_object.command, expected)
示例#8
0
 def testAlreadyExecuted(self):
     cmd = command.Command("", DUMMY_TIMEOUT_VALUE)
     self.assertFalse(cmd.already_executed())
     cmd.execute_in_shell()
     self.assertTrue(cmd.already_executed())
示例#9
0
 def test_str(self):
     cmd_object = command.Command("echo x")
     self.assertTrue(str(cmd_object))
示例#10
0
 def testWrappedCommand(self):
     wrapper = 'wrapper "%s"'
     cmd = "command"
     cmd_object = command.Command(cmd, wrapper=wrapper)
     expected = 'wrapper "command"'
     self.assertEquals(cmd_object.command, expected)
示例#11
0
 def testThisIsParentOfCommandWhenWithoutShell(self):
     cmd = command.Command("ps -o ppid= -C ps", DUMMY_TIMEOUT_VALUE)
     cmd.execute()
     self._assertStdout(cmd, "%s\n" % os.getpid())
示例#12
0
 def testThisIsParentOfShellWithExecuteInShell(self):
     cmd = command.Command("echo $PPID", DUMMY_TIMEOUT_VALUE)
     cmd.execute_in_shell()
     self._assertStdout(cmd, "%s\n" % os.getpid())
示例#13
0
 def testExecuteWithRetriesSuccessfulCommand(self):
     cmd = command.Command("echo jee")
     self.assertAlmostEquals(cmd.execute_with_retries(5, 0), 1)
示例#14
0
 def testExecuteWithRetriesTimeoutingCommand(self):
     cmd = command.Command("sleep 5", 0.2)
     self.failUnlessRaises(command.FailedAfterRetries,
                           cmd.execute_with_retries, 5, 5)
示例#15
0
 def testExecuteWithRetriesFailingCommand(self):
     cmd = command.Command("echo jee")
     self.failUnlessRaises(command.FailedAfterRetries,
                           cmd.execute_with_retries, 5, 5)