def test_remote_child_function(): for ip_address in ip_addresses: pyc = PythonChildProcess(ip_address=ip_address,command=partial(remote_test_func, a=1, b=2)) (stdin, stdout, stderr) = pyc.execute_child_process() stderr_out =stderr.readlines() stderr_out = [line.strip() for line in stderr_out if "pydev debugger" not in line] stdout_out = stdout.readlines()
def test_simple_pcp_list(): for ip_address in ip_addresses: command = ["python", get_test_functions_path(ip_address), "--callback=success_function"] pyc = PythonChildProcess(ip_address=ip_address,command=command) (stdin, stdout, stderr) = pyc.execute_child_process() stderr_out = stderr.readlines() stderr_out = [line.strip() for line in stderr_out if "pydev debugger" not in line] stdout_out = stdout.readlines() assert len("".join(stderr_out)) == 0, "Stderr not empty. Received: %s"%stderr_out assert len(stdout_out) == 1 and stdout_out[0].strip() == "Success", "Stdout not as expected. Received: %s"%stdout_out
def test_remote_graphics(): for ip_address in ip_addresses: command = ["python", get_test_functions_path(ip_address), "--callback=remote_graphics"] cp = PythonChildProcess(ip_address=ip_address,command=command,take_care_of_deconstruct=True) i, stdout, stderr = cp.execute_child_process() time.sleep(1) stderr_out = stderr.readlines() stdout_out = stdout.readlines() # assert len(stderr_out) == 0, "Stderr not empty. Received: %s"%stderr_out assert stdout_out[-1].strip() == "Success", "Stdout not as expected. Received: %s"%stdout_out
def test_kill_process_gently(): for ip_address in ip_addresses: command = ["python", get_test_functions_path(ip_address), "--callback=sleep_function"] cp = PythonChildProcess(ip_address, command) stdin , stdout, stderr = cp.execute_child_process() time.sleep(1) cp.kill() time.sleep(1) stdout_out = stdout.readlines() assert stdout_out[-1].strip() == "Interrupted" assert not cp.is_alive(), "Process is still alive, killing it did not work"
def test_kill_process_strongly(): for ip_address in ip_addresses: command = ["python", get_test_functions_path(ip_address), "--callback=hanging_sleep_function"] cp = PythonChildProcess(ip_address, command) stdin , stdout, stderr = cp.execute_child_process() time.sleep(1) cp.kill() time.sleep(1) assert cp.is_alive(), "Process terminated too soon. Check remote_test_functions.py implementation!" cp.kill(signal.SIGKILL) time.sleep(1) assert not cp.is_alive(), "Process is still alive, killing it did not work"
def test_kill_process_strongly(): for ip_address in ip_addresses: command = ["python", get_test_functions_path(ip_address), "--callback=hanging_sleep_function"] cp = PythonChildProcess(ip_address, command) stdin , stdout, stderr = cp.execute_child_process() time.sleep(1) cp.kill() time.sleep(1) assert cp.is_alive(), "Process terminated too soon. Check remote_test_functions.py implementation!" cp.kill(signal.SIGTERM) time.sleep(1) assert not cp.is_alive(), "Process is still alive, killing it did not work"
def test_interrupt_process_gently(): for ip_address in ip_addresses: command = ["python", get_test_functions_path(ip_address), "--callback=count_high"] cp = PythonChildProcess(ip_address, command) stdin , stdout, stderr = cp.execute_child_process() time.sleep(5) cp.kill() time.sleep(1) stdout_out = stdout.readlines() stderr_out = stderr.readlines() if cp.is_local(): assert stderr_out[-1].strip() == "KeyboardInterrupt" else: assert stdout_out[-1].strip() == "KeyboardInterrupt" assert not cp.is_alive(), "Process is still alive, killing it did not work"