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_log(daemon_setup, directory_setup): """The default `log` command executes without failing. This implies that the daemon runs and creates proper log files. """ execute_add('ls') wait_for_process(0) execute_log({}, directory_setup[0])
def test_log_specific(daemon_setup, directory_setup): """The logging command executes without failing. This implies that the daemon runs and creates proper log files. """ execute_add('sleep 0.5') wait_for_process(0) execute_log({}, directory_setup[0])
def test_log_failed(daemon_setup, directory_setup): """The logging command executes without failing. This implies that the daemon runs and creates proper log files. """ execute_add('testfailcommand') wait_for_process(0) execute_log({'key': 0}, directory_setup[0])
def test_log(daemon_setup): """The logging command executes without failing. This implies that the daemon is running and the stdout file in /tmp is properly created. """ execute_add({'command': 'sleep 0.5'}) wait_for_process(0) execute_show({'watch': False})
def test_show_specific_finished(daemon_setup, directory_setup): """The show command executes without failing. This implies that the daemon is running and the stdout file in /tmp is properly created. """ execute_add('ls') wait_for_process(0) execute_show({'watch': False, 'key': 0}, directory_setup[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']
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']
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_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'
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'
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') 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_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'
def test_restart_multiple(daemon_setup): """Restart a running command fails.""" execute_add('ls') execute_add('ls') execute_add('ls') execute_add('sleep 0.1') wait_for_process(3) # Restart the commands 0 and 3. This should clone the entries and add it to the queue. response = command_factory('pause')() command_factory('restart')({'keys': [0, 3]}) assert response['status'] == 'success' status = command_factory('status')() assert len(status['data']) == 6 assert status['data'][4]['path'] == status['data'][0]['path'] assert status['data'][4]['command'] == status['data'][0]['command'] assert status['data'][4]['status'] == 'queued' assert status['data'][5]['path'] == status['data'][3]['path'] assert status['data'][5]['command'] == status['data'][3]['command'] assert status['data'][5]['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_process(0) status = wait_for_process(1) assert status['data'][0]['status'] == 'done' assert status['data'][1]['status'] == 'done' assert status['data'][2]['status'] == 'queued'
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'
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'
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_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'
def test_waiting_pause(daemon_setup, multiple_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. """ # Setup multiple processes test case multiple_setup( max_processes=2, processes=1, sleep_time=2, ) # Add longer sleep command and pause all commands with `'wait': True` execute_add('sleep 5') command_factory('pause')({'wait': True}) # The paused daemon should wait for the processes to finish and handle finished status = wait_for_process(0) assert status['status'] == 'paused' assert status['data'][0]['status'] == 'done' assert status['data'][1]['status'] == 'running'
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 execute_add('sleep 4') # Pause the daemon and the process command_factory('pause')({'wait': False}) status = command_factory('status')() assert status['data'][0]['status'] == 'paused' time.sleep(5) # Start the daemon again assert that it is still running command_factory('start')() status = command_factory('status')() assert status['data'][0]['status'] == 'running' # Wait for the process to finish status = wait_for_process(0) assert status['data'][0]['status'] == 'done'
def test_log_multiple_mixed_success(daemon_setup, directory_setup): """The `log` command works for failed entries.""" execute_add('testfailcommand') execute_add('ls') wait_for_process(1) execute_log({'keys': [0, 1, 3]}, directory_setup[0])
def test_show_specific_finished(daemon_setup, directory_setup): """The client doesn't crash while trying to show a specific finished entry.""" execute_add('ls') wait_for_process(0) execute_show({'watch': False, 'keys': [0]}, directory_setup[0])
def test_log_specific_multiple_succeeded(daemon_setup, directory_setup): """The `log` command for multiple specific processes executes without failing.""" execute_add('ls') execute_add('testfailing') wait_for_process(1) execute_log({'keys': [0, 1]}, directory_setup[0])
def test_log_specific(daemon_setup, directory_setup): """The `log` command for specific processes executes without failing.""" execute_add('ls') wait_for_process(0) execute_log({'keys': [0]}, directory_setup[0])
def test_log_failing(daemon_setup, directory_setup): """The `log` command works with keys of running or non existent entries.""" execute_add('ls') wait_for_process(0) execute_log({'keys': [0, 1, 3]}, directory_setup[0])