예제 #1
0
파일: test_pause.py 프로젝트: Nukesor/pueue
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'
예제 #2
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'
예제 #3
0
def test_remove_multiple_specific(daemon_setup):
    """Remove various entries from the queue."""
    # Pause the daemon.
    command_factory('pause')()

    # Add 4 entries to get a `failing`, `done`, `queued` and `running` entry.
    execute_add('failingtestcommand')
    execute_add('sleep 60')
    execute_add('ls')
    execute_add('ls')

    # Start 0, 1 and 2 and wait for the `failed` and `done` entry to finish.
    response = command_factory('start')({'keys': [0, 1, 2]})
    status = wait_for_processes([0, 2])

    assert status['data'][0]['status'] == 'failed'
    assert status['data'][1]['status'] == 'running'
    assert status['data'][2]['status'] == 'done'
    assert status['data'][3]['status'] == 'queued'

    # Remove all entries. The response should be an error, as we try to remove
    # a running process.
    response = command_factory('remove')({'keys': [0, 1, 2, 3]})
    assert response['status'] == 'error'

    status = command_factory('status')()
    assert 0 not in status['data']
    assert status['data'][1]['status'] == 'running'
    assert 2 not in status['data']
    assert 3 not in status['data']
예제 #4
0
파일: test_pause.py 프로젝트: Nukesor/pueue
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'
예제 #5
0
def test_kill(daemon_setup, signal):
    """Kill a running process."""
    execute_add('sleep 60')
    command_factory('kill')({'signal': signal})
    status = wait_for_process(0)
    assert status['status'] == 'paused'
    assert status['data'][0]['status'] == 'failed'
예제 #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_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'
예제 #8
0
def test_stash_paused(daemon_setup):
    """Stash a paused process."""
    # Add process and pause it
    execute_add('sleep 60')
    command_factory('pause')()
    # Stash it, but it should fail
    status = command_factory('stash')({'key': 0})
    assert status['status'] == 'error'
예제 #9
0
def test_reset_running(daemon_setup):
    """Reset a daemon with running subprocesses."""
    command_factory('start')()
    execute_add('sleep 60')
    execute_add('sleep 60')
    command_factory('reset')()
    status = command_factory('status')()
    assert status['status'] == 'running'
    assert status['data'] == 'Queue is empty'
예제 #10
0
def test_switch(daemon_setup):
    """Switch the position of two commands in the queue."""
    command_factory('pause')()
    execute_add('ls')
    execute_add('ls -l')
    command_factory('switch')({'first': 0, 'second': 1})
    status = command_factory('status')()
    assert status['data'][0]['command'] == 'ls -l'
    assert status['data'][1]['command'] == 'ls'
예제 #11
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'
예제 #12
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'
예제 #13
0
def test_reset_paused(daemon_setup):
    """Reset the daemon."""
    command_factory('pause')()
    execute_add('sleep 60')
    execute_add('sleep 60')
    command_factory('reset')()
    status = command_factory('status')()
    assert status['status'] == 'paused'
    assert status['data'] == 'Queue is empty'
예제 #14
0
 def setup(processes=4, max_processes=3, sleep_time=60):
     # Set max processes to three concurrent processes
     command_factory('config')({
         "option": "maxProcesses",
         "value": max_processes,
     })
     # Add sleep commands
     for i in range(processes):
         execute_add('sleep {}'.format(sleep_time))
예제 #15
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'
예제 #16
0
def test_restart_running(daemon_setup):
    """Restart a running command fails."""
    execute_add('sleep 5')
    response = command_factory('restart')({'keys': [0]})
    assert response['status'] == 'error'

    # There is still only one running entry in the queue
    status = command_factory('status')()
    assert len(status['data']) == 1
    assert status['data'][0]['status'] == 'running'
예제 #17
0
def test_add(daemon_setup):
    """The daemon adds a  new task to its queue."""
    response = command_factory('add')({
        'command': 'ls',
        'path': '/tmp',
    })
    assert response['status'] == 'success'
    status = command_factory('status')()
    assert status['data'][0]['command'] == 'ls'
    assert status['data'][0]['path'] == '/tmp'
예제 #18
0
def test_restart(daemon_setup):
    """Restart a command."""
    execute_add('ls')
    wait_for_process(0)
    response = command_factory('restart')({'key': 0})
    assert response['status'] == 'success'
    status = command_factory('status')()
    assert len(status['data']) == 2
    assert status['data'][1]['path'] == status['data'][0]['path']
    assert status['data'][1]['command'] == status['data'][0]['command']
예제 #19
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"
예제 #20
0
def test_remove(daemon_setup):
    """Remove a process from the queue."""
    command_factory('pause')()
    status = command_factory('status')()
    assert status['status'] == 'paused'
    execute_add('ls')

    response = command_factory('remove')({'key': 0})
    assert response['status'] == 'success'
    status = command_factory('status')()
    assert status['data'] == 'Queue is empty'
예제 #21
0
def test_pause(daemon_setup):
    """Pause the daemon."""
    # Assert that the daemon is running after setup
    status = command_factory('status')()
    assert status['status'] == 'running'

    # Add a single command
    execute_add('sleep 60')
    command_factory('pause')()
    status = command_factory('status')()
    assert status['status'] == 'paused'
    assert status['data'][0]['status'] == 'paused'
예제 #22
0
def test_remove(daemon_setup):
    """Remove a process from the queue."""
    # Pause the daemon. Otherwise we may try to remove a running entry.
    command_factory('pause')()

    # Add entry and instantly remove it.
    execute_add('ls')
    response = command_factory('remove')({'keys': [0]})
    assert response['status'] == 'success'

    # The queue should be empty
    status = command_factory('status')()
    assert status['data'] == 'Queue is empty'
예제 #23
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'
예제 #24
0
def test_kill_single(daemon_setup):
    """Kill a running process and check if it finishes as failed."""
    # We need to add some bash syntax with "&&" otherwise python won't spawn a
    # shell parent process. But we need this for debugging.
    execute_add('sleep 60 && ls')

    # Unfortunately this is necessary as the shell parent process needs some time to spawn it's children
    time.sleep(1)
    # Kill the children of the parent process
    command_factory('kill')({'keys': [0], 'signal': 'sigkill'})
    command_factory('status')()
    status = wait_for_process(0)
    assert status['status'] == 'running'
    assert status['data'][0]['status'] == 'failed'
예제 #25
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 and pause it with `'wait': True`
    execute_add('sleep 2')
    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'
예제 #26
0
def test_restart(daemon_setup):
    """Restart a command."""
    # Add command and let it finish
    execute_add('sleep 1')
    wait_for_process(0)

    # Restart the command. This should clone the entry and add it to the queue.
    response = command_factory('restart')({'keys': [0]})
    assert response['status'] == 'success'

    status = command_factory('status')()
    assert len(status['data']) == 2
    assert status['data'][1]['path'] == status['data'][0]['path']
    assert status['data'][1]['command'] == status['data'][0]['command']
    assert status['data'][1]['status'] == 'running'
def test_pause_multiple(daemon_setup, multiple_setup):
    """Pause the daemon with multiple running processes."""
    # Setup multiple processes test case
    multiple_setup(
        max_processes=3,
        processes=4,
        sleep_time=60,
    )
    # Pause and check if all running processes have been paused
    command_factory('pause')()
    status = command_factory('status')()
    assert status['status'] == 'paused'
    assert status['data'][0]['status'] == 'paused'
    assert status['data'][1]['status'] == 'paused'
    assert status['data'][2]['status'] == 'paused'
    assert status['data'][3]['status'] == 'queued'
예제 #28
0
def test_kill_all(daemon_setup, multiple_setup, signal):
    """Kill all running processes."""
    # Setup multiple processes test case
    multiple_setup(
        max_processes=3,
        processes=4,
        sleep_time=60,
    )

    command_factory('kill')({'signal': signal})
    status = wait_for_processes([0, 1, 2])
    assert status['status'] == 'paused'
    assert status['data'][0]['status'] == 'failed'
    assert status['data'][1]['status'] == 'failed'
    assert status['data'][2]['status'] == 'failed'
    assert status['data'][3]['status'] == 'queued'
예제 #29
0
파일: test_pause.py 프로젝트: Nukesor/pueue
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'
def test_stash_running(daemon_setup):
    """Stash a running process."""
    # Add sleep entry
    execute_add('sleep 60')

    # Try to stash it, but it should fail
    status = command_factory('stash')({'keys': [0]})
    assert status['status'] == 'error'
예제 #31
0
def test_kill_shell_of_single_with_multiple_commands(daemon_setup):
    """Assure that the signal will be sent to the shell process with '-a' provided."""
    # Once the first sleep finishes the second sleep process will be spawned.
    # By this we can assure that the signal is only sent to the child processes.
    execute_add('sleep 60 ; sleep 60')

    # Unfortunately this is necessary as the shell parent process needs some time to spawn it's children
    time.sleep(1)

    # Kill the shell process as well as the child processes.
    command_factory('kill')({'keys': [0], 'signal': 'sigkill', 'all': True})

    # Give the shell process some time to die and pueue to clean up the mess.
    status = wait_for_process(0)
    # Assert that the queue entry is finished and failed
    assert status['status'] == 'running'
    assert status['data'][0]['status'] == 'failed'
예제 #32
0
def test_remove_multiple_specific_success(daemon_setup):
    """Remove various entries from the queue."""
    # Pause the daemon.
    command_factory('pause')()

    # Add entries
    execute_add('ls')
    execute_add('ls')
    execute_add('ls')

    # Remove two entries.
    response = command_factory('remove')({'keys': [0, 1]})
    assert response['status'] == 'success'

    status = command_factory('status')()
    assert 0 not in status['data']
    assert 1 not in status['data']
예제 #33
0
파일: conftest.py 프로젝트: Nukesor/pueue
def daemon_setup(request):
    queue = create_config_dir()+'/queue'
    if os.path.exists(queue):
        os.remove(queue)

    process = subprocess.Popen(
        'pueue --daemon',
        shell=True,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE
    )
    output, error = process.communicate()
    command_factory('reset')

    def daemon_teardown():
        command_factory('reset')
        command_factory('STOPDAEMON')
    request.addfinalizer(daemon_teardown)
예제 #34
0
def test_stash(daemon_setup):
    """Kill a running process."""
    # Pause daemon to prevent the process to start
    command_factory('pause')()
    # Add process
    execute_add('sleep 60')
    # Stash it
    command_factory('stash')({'key': 0})
    # Check if it's stashed
    status = command_factory('status')()
    assert status['status'] == 'paused'
    assert status['data'][0]['status'] == 'stashed'

    # Enqueue, start and ensure that its running
    command_factory('enqueue')({'key': 0})
    command_factory('start')()
    status = command_factory('status')()
    assert status['data'][0]['status'] == 'running'
예제 #35
0
def test_kill_multiple(daemon_setup, multiple_setup, signal):
    """Kill multiple running processes."""
    # Setup multiple processes test case
    multiple_setup(
        max_processes=3,
        processes=4,
        sleep_time=60,
    )

    # Only kill two of three running processes and wait for them being processed.
    command_factory('kill')({'keys': [0, 2], 'signal': signal})
    status = wait_for_processes([0, 2])

    # Two should be failed, and two should be running
    assert status['status'] == 'running'
    assert status['data'][0]['status'] == 'failed'
    assert status['data'][1]['status'] == 'running'
    assert status['data'][2]['status'] == 'failed'
    assert status['data'][3]['status'] == 'running'
예제 #36
0
def test_kill_single_with_multiple_commands(daemon_setup):
    """Assure that the signal will be only send to the shells child processes."""
    # Once the first sleep finishes the second sleep process will be spawned.
    # By this we can assure that the signal is only sent to the child processes.
    execute_add('sleep 60 ; sleep 60')

    # Unfortunately this is necessary as the shell parent process needs some time to spawn it's children
    time.sleep(1)

    # Kill the children of the parent process
    command_factory('kill')({'keys': [0], 'signal': 'sigkill'})

    # Give the shell process some time to clean the old process and spawn the new one.
    time.sleep(1)

    # Assert that the queue entry is still running
    status = command_factory('status')()
    assert status['status'] == 'running'
    assert status['data'][0]['status'] == 'running'
def test_pause_multiple_specific(daemon_setup, multiple_setup):
    """Pause specific entries of a daemon with multiple running processes."""
    # Setup multiple processes test case
    multiple_setup(
        max_processes=3,
        processes=4,
        sleep_time=60,
    )
    # Pause specific valid entries. The response should be a success.
    response = command_factory('pause')({'keys': [0, 1]})
    assert response['status'] == 'success'

    # Assert that all keys have been paused. The daemon should be still running.
    status = command_factory('status')()
    assert status['status'] == 'running'
    assert status['data'][0]['status'] == 'paused'
    assert status['data'][1]['status'] == 'paused'
    assert status['data'][2]['status'] == 'running'
    assert status['data'][3]['status'] == 'queued'
def test_waiting_pause_multiple(daemon_setup, multiple_setup):
    """Daemon waits for processes to finish.

    With `wait=True` as a parameter the daemon pauses,
    but waits for the current processes to finish instead of
    pausing them.
    """
    # Setup multiple processes test case
    multiple_setup(
        max_processes=2,
        processes=3,
        sleep_time=3,
    )

    # Pause the daemon with `'wait': True`
    command_factory('pause')({'wait': True})
    # The paused daemon should wait for the processes to finish
    status = wait_for_processes([0, 1])
    assert status['data'][0]['status'] == 'done'
    assert status['data'][1]['status'] == 'done'
    assert status['data'][2]['status'] == 'queued'
예제 #39
0
def test_kill_remove_resume(daemon_setup):
    """Old `done` and `failed` entries will be deleted."""

    # Add a command that fails, and finishes as well as queued and running processes
    execute_add('failingstufftest')
    execute_add('ls')
    execute_add('ls')
    execute_add('sleep 60')
    execute_add('ls')
    status = wait_for_process(2)

    # Trigger the clear
    command_factory('clear')()

    # Check that 0,1,2 are missing, 3 is 'running' and 4 is 'queued'
    status = command_factory('status')()
    assert 0 not in status['data']
    assert 1 not in status['data']
    assert 2 not in status['data']
    assert status['data'][3]['status'] == 'running'
    assert status['data'][4]['status'] == 'queued'
def test_multiple_stash_enqueue_invalid(daemon_setup):
    """Stash and enqueue multiple entries, but include invalid keys for enqueue."""
    # Pause daemon and add multiple entries
    command_factory('pause')()
    execute_add('ls')
    execute_add('sleep 1')
    execute_add('ls')

    # Stash all commands and ensure that they are stashed
    status = command_factory('stash')({'keys': [1, 2]})
    assert status['status'] == 'success'

    status = command_factory('status')()
    assert status['data'][0]['status'] == 'queued'
    assert status['data'][1]['status'] == 'stashed'
    assert status['data'][2]['status'] == 'stashed'

    # Enqueue all commands and ensure that they are queued
    # Response status should be `error` anyway, as we sent invalid keys
    status = command_factory('enqueue')({'keys': [0, 1, 2, 4]})
    assert status['status'] == 'error'

    status = command_factory('status')()
    assert status['data'][0]['status'] == 'queued'
    assert status['data'][1]['status'] == 'queued'
    assert status['data'][2]['status'] == 'queued'
예제 #41
0
def test_start_multiple_after_pause(daemon_setup, multiple_setup):
    """Daemon properly starts paused subprocesses."""
    # Setup multiple processes test case
    multiple_setup(
        max_processes=2,
        processes=2,
        sleep_time=3,
    )

    # Pause the daemon and the process
    command_factory('pause')({'wait': False})
    status = command_factory('status')()
    assert status['data'][0]['status'] == 'paused'
    assert status['data'][1]['status'] == 'paused'

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

    # Wait for the process to finish
    status = wait_for_process(0)
    status = wait_for_process(1)
    assert status['data'][0]['status'] == 'done'
    assert status['data'][1]['status'] == 'done'
def test_multiple_stash_enqueue(daemon_setup):
    """Stash and enqueue multiple valid entries."""
    # Pause daemon and add multiple entries
    command_factory('pause')()
    execute_add('ls')
    execute_add('sleep 1')
    execute_add('ls')

    # Stash all commands and ensure that they are stashed
    status = command_factory('stash')({'keys': [0, 1, 2]})
    assert status['status'] == 'success'

    status = command_factory('status')()
    assert status['data'][0]['status'] == 'stashed'
    assert status['data'][1]['status'] == 'stashed'
    assert status['data'][2]['status'] == 'stashed'

    # Enqueue all commands and ensure that they are queued
    status = command_factory('enqueue')({'keys': [0, 1, 2]})
    assert status['status'] == 'success'

    status = command_factory('status')()
    assert status['data'][0]['status'] == 'queued'
    assert status['data'][1]['status'] == 'queued'
    assert status['data'][2]['status'] == 'queued'
예제 #43
0
파일: conftest.py 프로젝트: Nukesor/pueue
 def daemon_teardown():
     command_factory('reset')
     command_factory('STOPDAEMON')
예제 #44
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'