Пример #1
0
    def test_successful_stop(self):
        """
        test stopWorker() on a successful worker stop
        """

        def emulated_kill(pid, sig):
            if sig == 0:
                # when probed if a signal can be send to the process
                # emulate that it is dead with 'No such process' error
                raise OSError(errno.ESRCH, "dummy")

        # patch open() to return a pid file
        self.setUpOpen(str(self.PID))

        # patch os.kill to emulate successful kill
        mocked_kill = mock.Mock(side_effect=emulated_kill)
        self.patch(os, "kill", mocked_kill)

        # don't waste time
        self.patch(time, "sleep", mock.Mock())

        # check that stopWorker() sends expected signal to right PID
        # and print correct message to stdout
        stop.stopWorker(None, False)
        mocked_kill.assert_has_calls([mock.call(self.PID, signal.SIGTERM),
                                      mock.call(self.PID, 0)])

        self.assertStdoutEqual("worker process %s is dead\n" % self.PID)
Пример #2
0
    def test_successful_stop(self):
        """
        test stopWorker() on a successful worker stop
        """
        def emulated_kill(pid, sig):
            if sig == 0:
                # when probed if a signal can be send to the process
                # emulate that it is dead with 'No such process' error
                raise OSError(errno.ESRCH, "dummy")

        # patch open() to return a pid file
        self.setUpOpen(str(self.PID))

        # patch os.kill to emulate successful kill
        mocked_kill = mock.Mock(side_effect=emulated_kill)
        self.patch(os, "kill", mocked_kill)

        # don't waste time
        self.patch(time, "sleep", mock.Mock())

        # check that stopWorker() sends expected signal to right PID
        # and print correct message to stdout
        stop.stopWorker(None, False)
        mocked_kill.assert_has_calls(
            [mock.call(self.PID, signal.SIGTERM),
             mock.call(self.PID, 0)])

        self.assertStdoutEqual("worker process %s is dead\n" % self.PID)
Пример #3
0
    def test_no_pid_file(self):
        """
        test calling stopWorker() when no pid file is present
        """

        # patch open() to raise 'file not found' exception
        self.setUpOpenError(2)

        # check that stop() raises WorkerNotRunning exception
        with self.assertRaises(stop.WorkerNotRunning):
            stop.stopWorker(None, False)
Пример #4
0
    def test_no_pid_file(self):
        """
        test calling stopWorker() when no pid file is present
        """

        # patch open() to raise 'file not found' exception
        self.setUpOpenError(2)

        # check that stop() raises WorkerNotRunning exception
        with self.assertRaises(stop.WorkerNotRunning):
            stop.stopWorker(None, False)
Пример #5
0
def restart(config):
    quiet = config['quiet']
    basedir = config['basedir']

    if not base.isWorkerDir(basedir):
        return 1

    try:
        stop.stopWorker(basedir, quiet)
    except stop.WorkerNotRunning:
        if not quiet:
            log.msg("no old worker process found to stop")
    if not quiet:
        log.msg("now restarting worker process..")

    return start.startWorker(basedir, quiet, config['nodaemon'])
Пример #6
0
    def test_stop_timeout(self):
        """
        test stopWorker() when stop timeouts
        """

        # patch open() to return a pid file
        self.setUpOpen(str(self.PID))

        # patch os.kill to emulate successful kill
        mocked_kill = mock.Mock()
        self.patch(os, "kill", mocked_kill)

        # don't waste time
        self.patch(time, "sleep", mock.Mock())

        # check that stopWorker() sends expected signal to right PID
        # and print correct message to stdout
        exit_code = stop.stopWorker(None, False)
        self.assertEqual(exit_code, 1)
        mocked_kill.assert_has_calls([mock.call(self.PID, signal.SIGTERM),
                                      mock.call(self.PID, 0)])

        self.assertStdoutEqual("never saw process go away\n")
    def test_stop_timeout(self):
        """
        test stopWorker() when stop timeouts
        """

        # patch open() to return a pid file
        self.setUpOpen(str(self.PID))

        # patch os.kill to emulate successful kill
        mocked_kill = mock.Mock()
        self.patch(os, "kill", mocked_kill)

        # don't waste time
        self.patch(time, "sleep", mock.Mock())

        # check that stopWorker() sends expected signal to right PID
        # and print correct message to stdout
        exit_code = stop.stopWorker(None, False)
        self.assertEqual(exit_code, 1)
        mocked_kill.assert_has_calls([mock.call(self.PID, signal.SIGTERM),
                                      mock.call(self.PID, 0)])

        self.assertStdoutEqual("never saw process go away\n")