Skip to content

Commit

Permalink
draft revert old test_start_interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
dmyger committed Oct 20, 2024
1 parent 21f3f17 commit 70c541c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
42 changes: 27 additions & 15 deletions test/integration/running/test_running.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
24 changes: 24 additions & 0 deletions test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 70c541c

Please sign in to comment.