From f1107174e150b7fb0e08e2423fea199491aeac8c Mon Sep 17 00:00:00 2001 From: Dmitriy Gertsog Date: Sat, 19 Oct 2024 12:38:50 +0300 Subject: [PATCH] draft revert old test_start_interactive --- test/integration/running/test_running.py | 42 +++++++++++++++--------- test/utils.py | 24 ++++++++++++++ 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/test/integration/running/test_running.py b/test/integration/running/test_running.py index 2f58d0829..fb067c9e9 100644 --- a/test/integration/running/test_running.py +++ b/test/integration/running/test_running.py @@ -10,12 +10,11 @@ import yaml from retry import retry -from utils import (ProcessTextPipe, config_name, control_socket, - extract_status, initial_snap, initial_xlog, - kill_child_process, lib_path, log_file, log_path, pid_file, - pipe_wait_all, run_command_and_get_output, run_path, - wait_file, wait_instance_start, wait_instance_stop, - wait_string_in_file) +from utils import (config_name, control_socket, extract_status, initial_snap, + initial_xlog, kill_child_process, lib_path, log_file, + log_path, pid_file, run_command_and_get_output, run_path, + wait_file, wait_for_lines_in_output, wait_instance_start, + wait_instance_stop, wait_string_in_file) def test_running_base_functionality(tt_cmd, tmpdir_with_cfg): @@ -936,22 +935,35 @@ def test_start_interactive(tt_cmd, tmp_path): tmp_path /= "multi_inst_app" shutil.copytree(test_app_path_src, tmp_path) - with ProcessTextPipe((tt_cmd, "start", "-i"), tmp_path) as instance_process: - pipe_wait_all( - instance_process, + start_cmd = [tt_cmd, "start", "-i"] + instance_process = subprocess.Popen( + start_cmd, + cwd=tmp_path, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, + text=True + ) + try: + wait_for_lines_in_output(instance_process.stdout, [ "multi_inst_app:router custom init file...", "multi_inst_app:router multi_inst_app:router", "multi_inst_app:master multi_inst_app:master", "multi_inst_app:replica multi_inst_app:replica", "multi_inst_app:stateboard unknown instance", - ) + ]) + instance_process.send_signal(signal.SIGTERM) - pipe_wait_all( - instance_process, + + wait_for_lines_in_output(instance_process.stdout, [ "multi_inst_app:router stopped", "multi_inst_app:master stopped", "multi_inst_app:replica stopped", "multi_inst_app:stateboard stopped", - line_timeout=5 - ) - assert instance_process.Stop(tt_cmd, "stop", "--yes", timeout=5) == 0 + ]) + + # Make sure no log dir created. + assert not (tmp_path / "var" / "log").exists() + + finally: + run_command_and_get_output([tt_cmd, "stop", "--yes"], cwd=tmp_path) + assert instance_process.wait(5) == 0 diff --git a/test/utils.py b/test/utils.py index 671affee2..82694bef3 100644 --- a/test/utils.py +++ b/test/utils.py @@ -557,6 +557,30 @@ def wait_string_in_file(file, text): assert found +def wait_for_lines_in_output(stdout, expected_lines: list): + output = "" + retries = 10 + while True: + line = stdout.readline() + if line == "": + if retries == 0: + break + time.sleep(0.2) + retries -= 1 + else: + retries = 10 + output += line + for expected in expected_lines: + if expected in line: + expected_lines.remove(expected) + break + + if len(expected_lines) == 0: + break + + return output + + class ProcessTextPipe(subprocess.Popen): __cwd: str | Path