diff --git a/test/integration/running/test_running.py b/test/integration/running/test_running.py index 8faca363b..6cec5e1d7 100644 --- a/test/integration/running/test_running.py +++ b/test/integration/running/test_running.py @@ -14,7 +14,7 @@ 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_instance_stop, wait_string_in_file) def test_running_base_functionality(tt_cmd, tmpdir_with_cfg): @@ -578,51 +578,48 @@ def test_running_env_variables(tt_cmd, tmpdir_with_cfg): # Copy the test application to the "run" directory. test_app_path = os.path.join(os.path.dirname(__file__), "test_env_app", "test_env_app.lua") shutil.copy(test_app_path, tmpdir) + # Set environmental variable which changes log format to json. my_env = os.environ.copy() my_env["TT_LOG_FORMAT"] = "json" - # Start an instance with custom env. - start_cmd = [tt_cmd, "start", "test_env_app"] - instance_process = subprocess.Popen( - start_cmd, - cwd=tmpdir, - stderr=subprocess.STDOUT, - stdout=subprocess.PIPE, - text=True, - env=my_env - ) - start_output = instance_process.stdout.readline() - assert re.search(r"Starting an instance", start_output) - # Check status. - file = wait_file(os.path.join(tmpdir, "test_env_app", run_path, "test_env_app"), pid_file, []) - assert file != "" - status_cmd = [tt_cmd, "status", "test_env_app"] - status_rc, status_out = run_command_and_get_output(status_cmd, cwd=tmpdir) - assert status_rc == 0 - status_out = extract_status(status_out) - assert status_out["test_env_app"]["STATUS"] == "RUNNING" - - # Stop the Instance. - stop_cmd = [tt_cmd, "stop", "-y", "test_env_app"] - stop_rc, stop_out = run_command_and_get_output(stop_cmd, cwd=tmpdir) - assert stop_rc == 0 - assert re.search(r"The Instance test_env_app \(PID = \d+\) has been terminated.", stop_out) + try: + # Start an instance with custom env. + start_cmd = [tt_cmd, "start", "test_env_app"] + instance_process = subprocess.Popen( + start_cmd, + cwd=tmpdir, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, + text=True, + env=my_env + ) + start_output = instance_process.stdout.readline() + assert re.search(r"Starting an instance", start_output) - # Check that the process was terminated correctly. - instance_process_rc = instance_process.wait(1) - assert instance_process_rc == 0 + # Check status. + file = wait_file(os.path.join(tmpdir, "test_env_app", run_path, "test_env_app"), + pid_file, []) + assert file != "" + status_cmd = [tt_cmd, "status", "test_env_app"] + status_rc, status_out = run_command_and_get_output(status_cmd, cwd=tmpdir) + assert status_rc == 0 + status_out = extract_status(status_out) + assert status_out["test_env_app"]["STATUS"] == "RUNNING" - # Check that log format is in json. - isJson = False - logPath = os.path.join(tmpdir, "test_env_app", "var", "log", "test_env_app", log_file) - with open(logPath, "r") as file: - for _, line in enumerate(file, start=1): - if "{" in line: - isJson = True - break + # Check that log format is in json. + logPath = os.path.join(tmpdir, "test_env_app", "var", "log", "test_env_app", log_file) + wait_string_in_file(logPath, "{") + finally: + # Stop the Instance. + stop_cmd = [tt_cmd, "stop", "-y", "test_env_app"] + stop_rc, stop_out = run_command_and_get_output(stop_cmd, cwd=tmpdir) + assert stop_rc == 0 + assert re.search(r"The Instance test_env_app \(PID = \d+\) has been terminated.", stop_out) - assert isJson + # Check that the process was terminated correctly. + instance_process_rc = instance_process.wait(1) + assert instance_process_rc == 0 def test_running_tarantoolctl_layout(tt_cmd, tmp_path):