示例#1
0
def test_pause(daemon_setup):
    """Pause the daemon."""
    status = get_status()
    assert status['status'] == 'running'
    command_factory('pause')
    status = get_status()
    assert status['status'] == 'paused'
示例#2
0
def test_start_after_pause(daemon_setup):
    """Daemon really pauses subprocess.

    In case the subprocess doesn't pause, the command should complete instantly
    after starting the daemon again.
    """
    # Add command and make sure it's running
    execute_add({'command': 'sleep 2 && sleep 2'})
    status = get_status()
    assert status['status'] == 'running'

    # Pause the daemon and the process
    command_factory('pause', {'wait': False})
    status = get_status()
    assert status['data'][0]['status'] == 'paused'
    time.sleep(5)

    # Start the daemon again assert that it is still running
    command_factory('start')
    status = get_status()
    assert status['data'][0]['status'] == 'running'

    # Wait for the process to finish
    status = wait_for_process(0)
    assert status['status'] == 'running'
    assert status['data'][0]['status'] == 'done'
示例#3
0
def test_remove(daemon_setup):
    """Remove a process from the queue."""
    command_factory("pause")
    status = get_status()
    assert status["status"] == "paused"
    execute_add({"command": "ls"})

    response = send_command({"mode": "remove", "key": 0})
    assert response["status"] == "success"
    status = get_status()
    assert status["data"] == "Queue is empty"
示例#4
0
def test_kill(daemon_setup):
    """Kill a running process."""
    execute_add({'command': 'sleep 60'})
    command_factory('kill', {'remove': False})
    status = get_status()
    assert status['status'] == 'paused'
    assert status['process'] == 'No running process'
示例#5
0
def test_stop_remove(daemon_setup):
    """Stop a running process and remove it afterwards."""
    execute_add({'command': 'sleep 2'})
    command_factory('stop', {'remove': True})
    status = get_status()
    assert status['status'] == 'paused'
    assert status['process'] == 'No running process'
    assert status['data'] == 'Queue is empty'
示例#6
0
文件: test_add.py 项目: Nukesor/pueue
def test_add(daemon_setup):
    """The daemon adds a  new task to its queue."""
    command_factory("pause")
    response = send_command({"mode": "add", "command": "ls", "path": "/tmp", "status": "queued", "returncode": ""})
    assert response["status"] == "success"
    status = get_status()
    assert status["data"][0]["command"] == "ls"
    assert status["data"][0]["path"] == "/tmp"
示例#7
0
def test_reset_running(daemon_setup):
    """Reset a daemon with running subprocesses."""
    command_factory('start')
    execute_add({'command': 'sleep 60'})
    execute_add({'command': 'sleep 60'})
    command_factory('reset')
    status = get_status()
    assert status['status'] == 'running'
    assert status['data'] == 'Queue is empty'
示例#8
0
def test_reset_paused(daemon_setup):
    """Reset the daemon."""
    command_factory('pause')
    execute_add({'command': 'sleep 60'})
    execute_add({'command': 'sleep 60'})
    command_factory('reset')
    status = get_status()
    assert status['status'] == 'paused'
    assert status['data'] == 'Queue is empty'
示例#9
0
def test_switch(daemon_setup):
    """Switch the position of two commands in the queue."""
    command_factory('pause')
    execute_add({'command': 'ls'})
    execute_add({'command': 'ls -l'})
    command_factory('switch', {'first': 0, 'second': 1})
    status = get_status()
    assert status['data'][0]['command'] == 'ls -l'
    assert status['data'][1]['command'] == 'ls'
示例#10
0
def test_restart(daemon_setup):
    """Restart a command."""
    execute_add({'command': 'ls'})
    wait_for_process(0)
    response = send_command({'mode': 'restart', 'key': 0})
    assert response['status'] == 'success'
    status = get_status()
    assert len(status['data']) == 2
    assert status['data'][1]['path'] == status['data'][0]['path']
    assert status['data'][1]['command'] == status['data'][0]['command']
示例#11
0
def test_stop_remove_resume(daemon_setup):
    """Everything works properly after remove stopping a subprocess."""
    # Add status
    execute_add({'command': 'sleep 2'})
    command_factory('stop', {'remove': True})
    status = get_status()
    assert status['status'] == 'paused'
    # Old process should be
    execute_add({'command': 'sleep 2'})
    command_factory('start')
    status = wait_for_process(1)
    assert status['status'] == 'running'
    assert status['data'][1]['status'] == 'done'
示例#12
0
def test_waiting_pause(daemon_setup):
    """Daemon waits for process to finish.

    With `wait=True` as a parameter the daemon pauses,
    but waits for the current process to finish instead of
    pausing it.
    """
    # Add sleep command
    execute_add({'command': 'sleep 2'})
    status = get_status()
    assert status['status'] == 'running'
    # Pause it with `'wait': True`
    command_factory('pause', {'wait': True})
    # The paused daemon should wait for the process to finish
    status = wait_for_process(0)
    assert status['status'] == 'paused'
    assert status['data'][0]['status'] == 'done'
示例#13
0
def test_start(daemon_setup):
    """Start daemon after it has been paused."""
    command_factory('pause')
    command_factory('start')
    status = get_status()
    assert status['status'] == 'running'