Exemplo n.º 1
0
    def test_other_error(self):
        """Test raising other OSError."""
        err = OSError()
        err.errno = 4
        self.mock.killpg.side_effect = err

        with self.assertRaises(OSError) as cm:
            common.kill(self.proc)

        self.assertEqual(4, cm.exception.errno)
Exemplo n.º 2
0
    def test_succeed(self):
        """Test killing successfully."""
        self.mock.killpg.side_effect = [
            None, None, None, self.no_process_error
        ]
        common.kill(self.proc)

        self.assert_exact_calls(self.mock.killpg, [
            mock.call(1234, signal.SIGTERM),
            mock.call(1234, signal.SIGTERM),
            mock.call(1234, signal.SIGKILL),
            mock.call(1234, signal.SIGKILL)
        ])
        self.assert_exact_calls(self.mock.sleep, [mock.call(3)] * 3)
Exemplo n.º 3
0
    def test_fail(self):
        """Test failing to kill."""
        self.mock.killpg.side_effect = [None, None, None, None]

        with self.assertRaises(error.KillProcessFailedError) as cm:
            common.kill(self.proc)

        self.assertEqual('`cmd` (pid=1234) cannot be killed.',
                         cm.exception.message)

        self.assert_exact_calls(self.mock.killpg, [
            mock.call(1234, signal.SIGTERM),
            mock.call(1234, signal.SIGTERM),
            mock.call(1234, signal.SIGKILL),
            mock.call(1234, signal.SIGKILL)
        ])
        self.assert_exact_calls(self.mock.sleep, [mock.call(3)] * 4)