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"