Exemplo n.º 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)
Exemplo n.º 2
0
 def testHardTimeout(self):
     cmd = command.Command("sleep 5", 100, 0.5)
     self.failUnlessRaises(command.HardTimeoutException,
                           cmd.execute_in_shell)
Exemplo n.º 3
0
 def testGetExecutionTime(self):
     cmd = command.Command("sleep 0.5")
     cmd.execute_in_shell()
     self.assertAlmostEquals(cmd.execution_time, 0.5, 1)
Exemplo n.º 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)
Exemplo n.º 5
0
 def testGetStdout(self):
     cmd = command.Command("echo jee", DUMMY_TIMEOUT_VALUE)
     cmd.execute_in_shell()
     self._assertStdout(cmd, "jee\n")
Exemplo 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")
Exemplo n.º 7
0
 def testWrappedCommandWithEmptyWrapper(self):
     wrapper = ""
     cmd = "command"
     cmd_object = command.Command(cmd, wrapper=wrapper)
     expected = 'command'
     self.assertEquals(cmd_object.command, expected)
Exemplo n.º 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())
Exemplo n.º 9
0
 def test_str(self):
     cmd_object = command.Command("echo x")
     self.assertTrue(str(cmd_object))
Exemplo n.º 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)
Exemplo n.º 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())
Exemplo n.º 12
0
 def testThisIsParentOfShellWithExecuteInShell(self):
     cmd = command.Command("echo $PPID", DUMMY_TIMEOUT_VALUE)
     cmd.execute_in_shell()
     self._assertStdout(cmd, "%s\n" % os.getpid())
Exemplo n.º 13
0
 def testExecuteWithRetriesSuccessfulCommand(self):
     cmd = command.Command("echo jee")
     self.assertAlmostEquals(cmd.execute_with_retries(5, 0), 1)
Exemplo n.º 14
0
 def testExecuteWithRetriesTimeoutingCommand(self):
     cmd = command.Command("sleep 5", 0.2)
     self.failUnlessRaises(command.FailedAfterRetries,
                           cmd.execute_with_retries, 5, 5)
Exemplo n.º 15
0
 def testExecuteWithRetriesFailingCommand(self):
     cmd = command.Command("echo jee")
     self.failUnlessRaises(command.FailedAfterRetries,
                           cmd.execute_with_retries, 5, 5)