Esempio n. 1
0
def test_kill_custom_signal_kill():
    """Start process and shuts it down using signal SIGQUIT passed to kill."""
    executor = SimpleExecutor(sleep_300)
    executor.start()
    assert executor.running() is True
    executor.kill(sig=signal.SIGQUIT)
    assert executor.running() is False
Esempio n. 2
0
def test_kill_custom_signal_kill():
    """Start process and shuts it down using signal SIGQUIT passed to kill."""
    executor = SimpleExecutor(sleep_300)
    executor.start()
    assert executor.running() is True
    executor.kill(sig=signal.SIGQUIT)
    assert executor.running() is False
Esempio n. 3
0
def test_daemons_killing():
    """
    Test if all subprocesses of SimpleExecutor can be killed.

    The most problematic subprocesses are daemons or other services that
    change the process group ID. This test verifies that daemon process
    is killed after executor's kill().
    """
    executor = SimpleExecutor(('python', sample_daemon_path), shell=True)
    executor.start()
    time.sleep(2)
    assert executor.running() is not True, \
        "Executor should not have subprocess running as it started a daemon."

    assert sample_daemon_path in ps_aux()
    executor.kill()
    assert sample_daemon_path not in ps_aux()
Esempio n. 4
0
def test_daemons_killing():
    """
    Test if all subprocesses of SimpleExecutor can be killed.

    The most problematic subprocesses are daemons or other services that
    change the process group ID. This test verifies that daemon process
    is killed after executor's kill().
    """
    executor = SimpleExecutor(('python', sample_daemon_path), shell=True)
    executor.start()
    time.sleep(1)
    assert executor.running() is not True, \
        "Executor should not have subprocess running as it's started daemon."

    assert sample_daemon_path in ps_aux()
    executor.kill()
    assert sample_daemon_path not in ps_aux()

    # Second part of this test verifies exceptions being called if `ps xe -ww`
    # was called on some OS that doesn't have it.
    executor.start()
    time.sleep(1)

    def fake_output(args):
        check_output('something_not_existing_called')

    with mock.patch('subprocess.check_output', side_effect=fake_output) as co:
        with mock.patch('mirakuru.base.log') as log:
            executor.kill()

    assert co.mock_calls == [mock.call(('ps', 'xe', '-ww'))]
    assert 'error' == log.mock_calls[0][0]
    assert '`$ ps xe -ww` command was called' in log.mock_calls[0][1][0]

    assert sample_daemon_path in ps_aux()
    executor.kill()
    assert sample_daemon_path not in ps_aux()
Esempio n. 5
0
def test_daemons_killing():
    """
    Test if all subprocesses of SimpleExecutor can be killed.

    The most problematic subprocesses are daemons or other services that
    change the process group ID. This test verifies that daemon process
    is killed after executor's kill().
    """
    executor = SimpleExecutor(('python', sample_daemon_path), shell=True)
    executor.start()
    time.sleep(1)
    assert executor.running() is not True, \
        "Executor should not have subprocess running as it's started daemon."

    assert sample_daemon_path in ps_aux()
    executor.kill()
    assert sample_daemon_path not in ps_aux()

    # Second part of this test verifies exceptions being called if `ps xe -ww`
    # was called on some OS that doesn't have it.
    executor.start()
    time.sleep(1)

    def fake_output(args):
        check_output('something_not_existing_called')

    with mock.patch('subprocess.check_output', side_effect=fake_output) as co:
        with mock.patch('mirakuru.base.log') as log:
            executor.kill()

    assert co.mock_calls == [mock.call(('ps', 'xe', '-ww'))]
    assert 'error' == log.mock_calls[0][0]
    assert '`$ ps xe -ww` command was called' in log.mock_calls[0][1][0]

    assert sample_daemon_path in ps_aux()
    executor.kill()
    assert sample_daemon_path not in ps_aux()