Пример #1
0
 def test_timeout(self):
     timeout = 30
     cmd = Command(["/bin/sleep", str(timeout)], timeout=3)
     start_time = time.time()
     cmd.execute()
     # Check the process is no longer around.
     self.assertIsNotNone(cmd.getpid())
     self.assertRaises(ProcessLookupError, os.kill, cmd.getpid(), 0)
     elapsed_time = time.time() - start_time
     self.assertTrue(elapsed_time < timeout)
     self.assertEqual(Command.TIMEDOUT, cmd.getstate())
     self.assertEqual(None, cmd.getretcode())
Пример #2
0
def test_command_timeout(sleep_binary):
    timeout = 30
    cmd = Command([sleep_binary, str(timeout)], timeout=3)
    start_time = time.time()
    cmd.execute()
    # Check the process is no longer around.
    assert cmd.getpid() is not None
    with pytest.raises(ProcessLookupError):
        os.kill(cmd.getpid(), 0)
    elapsed_time = time.time() - start_time
    assert elapsed_time < timeout
    assert cmd.getstate() == Command.TIMEDOUT
    assert cmd.getretcode() is None
Пример #3
0
def test_command_timeout():
    timeout = 30
    cmd = Command(["/bin/sleep", str(timeout)], timeout=3)
    start_time = time.time()
    cmd.execute()
    # Check the process is no longer around.
    assert cmd.getpid() is not None
    with pytest.raises(ProcessLookupError):
        os.kill(cmd.getpid(), 0)
    elapsed_time = time.time() - start_time
    assert elapsed_time < timeout
    assert cmd.getstate() == Command.TIMEDOUT
    assert cmd.getretcode() is None