Ejemplo n.º 1
0
async def test_procmon_start_process_happy_path(logging_protocol_cls, monitor):
    start_event = Deferred()

    @monitor.once("startProcess")
    def on_start_process(state):
        assert state == ProcessState(
            name="some_process",
            state=LifecycleState.STOPPED,
            settings=ProcessSettings(
                restart=True,
                cleanup=False,
                threshold=1,
                killTime=5,
                minRestartDelay=1,
                maxRestartDelay=3600,
            ),
        )

        start_event.callback(None)

    monitor.addProcess("some_process", ["some", "argv"], restart=True)

    monitor.startProcess("some_process")

    await start_event.addTimeout(0.1, clock=reactor)

    assert monitor.protocols[
        "some_process"] == logging_protocol_cls.return_value
    assert monitor.protocols["some_process"].name == "some_process"
    assert monitor.protocols["some_process"].service == monitor
    assert isinstance(monitor.timeStarted["some_process"], float)
    monitor._spawnProcess.assert_called_once_with(
        monitor.protocols["some_process"],
        "some",
        ["some", "argv"],
        uid=None,
        gid=None,
        env=dict(),
        path=None,
    )

    assert monitor.getState("some_process") == ProcessState(
        name="some_process",
        state=LifecycleState.RUNNING,
        settings=ProcessSettings(
            restart=True,
            cleanup=False,
            threshold=1,
            killTime=5,
            minRestartDelay=1,
            maxRestartDelay=3600,
        ),
    )
Ejemplo n.º 2
0
    def on_connection_lost(state):
        assert state == ProcessState(
            name="some_process",
            state=LifecycleState.STOPPED,
            settings=ProcessSettings(
                restart=True,
                cleanup=False,
                threshold=1,
                killTime=5,
                minRestartDelay=0,
                maxRestartDelay=3600,
            ),
        )

        lost_event.callback(None)
Ejemplo n.º 3
0
    def on_start(state):
        assert state == ProcessState(
            name="some_process",
            state=LifecycleState.RESTARTING,
            settings=ProcessSettings(
                restart=True,
                cleanup=False,
                threshold=1,
                killTime=5,
                minRestartDelay=0,
                maxRestartDelay=3600,
            ),
        )

        restart_event.callback(None)
Ejemplo n.º 4
0
    def on_remove_process(state):
        assert state == ProcessState(
            name="some_process",
            state=LifecycleState.STOPPED,
            settings=ProcessSettings(
                restart=False,
                cleanup=True,
                threshold=None,
                killTime=None,
                minRestartDelay=None,
                maxRestartDelay=None,
            ),
        )

        remove_event.callback(None)
Ejemplo n.º 5
0
async def test_procmon_connection_lost_monitored_inactive(state, monitor):
    monitor.running = 1
    monitor.addProcess("some_process", ["some", "argv"],
                       restart=True,
                       minRestartDelay=0)

    monitor._setProcessState("some_process", state)

    monitor.protocols["some_process"] = Mock()

    lost_event = Deferred()

    @monitor.once("connectionLost")
    def on_connection_lost(state):
        assert state == ProcessState(
            name="some_process",
            state=LifecycleState.STOPPED,
            settings=ProcessSettings(
                restart=True,
                cleanup=False,
                threshold=1,
                killTime=5,
                minRestartDelay=0,
                maxRestartDelay=3600,
            ),
        )

        lost_event.callback(None)

    monitor.connectionLost("some_process")

    await lost_event.addTimeout(0.1, clock=reactor)

    assert "some_process" not in monitor.protocols
    assert "some_process" not in monitor.restart

    assert monitor.getState("some_process") == ProcessState(
        name="some_process",
        state=LifecycleState.STOPPED,
        settings=ProcessSettings(
            restart=True,
            cleanup=False,
            threshold=1,
            killTime=5,
            minRestartDelay=0,
            maxRestartDelay=3600,
        ),
    )
Ejemplo n.º 6
0
    monitor.assertRegistered("registered_process")


@pytest.mark.parametrize(
    "name,argv,kwargs,expected",
    [
        (
            "some_process",
            ["some", "argv"],
            dict(),
            ProcessState(
                name="some_process",
                state=LifecycleState.STOPPED,
                settings=ProcessSettings(
                    restart=False,
                    cleanup=True,
                    threshold=None,
                    killTime=None,
                    minRestartDelay=None,
                    maxRestartDelay=None,
                ),
            ),
        ),
        (
            "some_process",
            ["some", "argv"],
            dict(restart=True),
            ProcessState(
                name="some_process",
                state=LifecycleState.STOPPED,
                settings=ProcessSettings(
                    restart=True,