Skip to content

Commit

Permalink
tests: fix running env variables
Browse files Browse the repository at this point in the history
After updating tarantool sdk version to the 3.2.0 stopping instance in
`test_running_env_variables` causes an error with cleaning all logs in
json format that was written before. So it wasn't possible to determine
json format after stopping instance.

After the patch the order of distructing tarantool was moved to the
special `finally` block. Determination of json format was also updated
with `wait_string_in_file` function with special timeout.

Part of #931
  • Loading branch information
themilchenko authored and oleg-jukovec committed Sep 18, 2024
1 parent c3227c2 commit 2319f9e
Showing 1 changed file with 36 additions and 39 deletions.
75 changes: 36 additions & 39 deletions test/integration/running/test_running.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2319f9e

Please sign in to comment.