def test_atomiccmd__terminate_race_condition(temp_folder): cmd = AtomicCmd("true") cmd.run(temp_folder) while cmd._proc.poll() is None: pass cmd.terminate() assert_equal(cmd.join(), [0])
def test_atomiccmd__terminate_race_condition(temp_folder): cmd = AtomicCmd("true") cmd.run(temp_folder) while cmd._proc.poll() is None: pass cmd.terminate() assert_equal(cmd.join(), [0])
def test_pformat__simple__running__set_cwd(temp_folder): cmd = AtomicCmd(("sleep", "10"), set_cwd = True) cmd.run(temp_folder) assert_equal(pformat(cmd), ("<Command = ['sleep', '10']\n" " Status = Running ...\n" " STDOUT* = 'pipe_sleep_{id}.stdout'\n" " STDERR* = 'pipe_sleep_{id}.stderr'\n" " CWD = '{temp_dir}'>").format(id = id(cmd), temp_dir = temp_folder)) cmd.terminate() cmd.join()
def test_pformat__simple__running__set_cwd(temp_folder): cmd = AtomicCmd(("sleep", "10"), set_cwd=True) cmd.run(temp_folder) assert_equal(pformat(cmd), ("<Command = ['sleep', '10']\n" " Status = Running ...\n" " STDOUT* = 'pipe_sleep_{id}.stdout'\n" " STDERR* = 'pipe_sleep_{id}.stderr'\n" " CWD = '{temp_dir}'>").format(id=id(cmd), temp_dir=temp_folder)) cmd.terminate() cmd.join()
def test_pformat__simple__killed(temp_folder): cmd = AtomicCmd(("sleep", "10")) cmd.run(temp_folder) cmd.terminate() assert_equal(cmd.join(), ["SIGTERM"]) assert_equal(pformat(cmd), ("<Command = ['sleep', '10']\n" " Status = Terminated with signal SIGTERM\n" " STDOUT* = '{temp_dir}/pipe_sleep_{id}.stdout'\n" " STDERR* = '{temp_dir}/pipe_sleep_{id}.stderr'\n" " CWD = '{cwd}'>").format(id = id(cmd), temp_dir = temp_folder, cwd = os.getcwd()))
def test_pformat__simple__killed(temp_folder): cmd = AtomicCmd(("sleep", "10")) cmd.run(temp_folder) cmd.terminate() assert_equal(cmd.join(), ["SIGTERM"]) assert_equal(pformat(cmd), ("<Command = ['sleep', '10']\n" " Status = Terminated with signal SIGTERM\n" " STDOUT* = '{temp_dir}/pipe_sleep_{id}.stdout'\n" " STDERR* = '{temp_dir}/pipe_sleep_{id}.stderr'\n" " CWD = '{cwd}'>").format(id=id(cmd), temp_dir=temp_folder, cwd=os.getcwd()))
def _do_test_atomiccmd__terminate(temp_folder, raise_on_terminate): cmd = AtomicCmd(("sleep", "10")) cmd.run(temp_folder) killpg_was_called = [] def _wrap_killpg(pid, sig): assert_equal(pid, cmd._proc.pid) assert_equal(sig, signal.SIGTERM) killpg_was_called.append(True) if raise_on_terminate: raise OSError("KABOOM!") with Monkeypatch("os.killpg", _wrap_killpg): cmd.terminate() cmd.terminate() assert_equal(cmd.join(), ["SIGTERM"]) assert killpg_was_called
def test_atomiccmd__terminate_sigterm(temp_folder): cmd = AtomicCmd(("sleep", "10")) cmd.run(temp_folder) cmd.terminate() assert_equal(cmd.join(), ["SIGTERM"])
def test_atomiccmd__run__already_running(temp_files): cmd = AtomicCmd(("sleep", "10")) cmd.run(temp_files) assert_raises(CmdError, cmd.run, temp_files) cmd.terminate() cmd.join()
def test_atomiccmd__commit_while_running(temp_folder): cmd = AtomicCmd(("sleep", "10")) cmd.run(temp_folder) assert_raises(CmdError, cmd.commit, temp_folder) cmd.terminate() cmd.join()
def test_atomiccmd__terminate_sigterm(temp_folder): cmd = AtomicCmd(("sleep", "10")) cmd.run(temp_folder) cmd.terminate() assert_equal(cmd.join(), ["SIGTERM"])
def test_atomiccmd__terminate_after_join(temp_folder): cmd = AtomicCmd("true") cmd.run(temp_folder) assert_equal(cmd.join(), [0]) cmd.terminate() assert_equal(cmd.join(), [0])
def test_atomiccmd__run__exception_on_missing_command(temp_files): cmd = AtomicCmd(("xyzabcefgh", "10")) assert_raises(CmdError, cmd.run, temp_files) cmd.terminate() cmd.join()
def test_atomiccmd__run__already_running(temp_files): cmd = AtomicCmd(("sleep", "10")) cmd.run(temp_files) assert_raises(CmdError, cmd.run, temp_files) cmd.terminate() cmd.join()
def test_atomiccmd__commit_while_running(temp_folder): cmd = AtomicCmd(("sleep", "10")) cmd.run(temp_folder) assert_raises(CmdError, cmd.commit, temp_folder) cmd.terminate() cmd.join()
def test_atomiccmd__run__exception_on_missing_command__no_wrap(temp_files): cmd = AtomicCmd(("xyzabcefgh", "10")) assert_raises(OSError, cmd.run, temp_files, wrap_errors=False) cmd.terminate() cmd.join()
def test_atomiccmd__terminate_after_join(temp_folder): cmd = AtomicCmd("true") cmd.run(temp_folder) assert_equal(cmd.join(), [0]) cmd.terminate() assert_equal(cmd.join(), [0])
def test_atomiccmd__run__invalid_temp(temp_files): cmd = AtomicCmd(("sleep", "10")) assert_raises(CmdError, cmd.run, os.path.join(temp_files, "foo")) cmd.terminate() cmd.join()