Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions testgres/plugins/pg_probackup2/pg_probackup2/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ProbackupApp:

def __init__(self, test_class: unittest.TestCase,
pg_node, pb_log_path, test_env, auto_compress_alg, backup_dir, probackup_path=None):
self.process = None
self.test_class = test_class
self.pg_node = pg_node
self.pb_log_path = pb_log_path
Expand All @@ -60,8 +61,35 @@ def __init__(self, test_class: unittest.TestCase,
self.test_class.output = None
self.execution_time = None

def form_daemon_process(self, cmdline, env):
def stream_output(stream: subprocess.PIPE) -> None:
try:
for line in iter(stream.readline, ''):
print(line)
self.test_class.output += line
finally:
stream.close()

self.process = subprocess.Popen(
cmdline,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
env=env
)
logging.info(f"Process started in background with PID: {self.process.pid}")

if self.process.stdout and self.process.stderr:
stdout_thread = threading.Thread(target=stream_output, args=(self.process.stdout,), daemon=True)
stderr_thread = threading.Thread(target=stream_output, args=(self.process.stderr,), daemon=True)

stdout_thread.start()
stderr_thread.start()

return self.process.pid

def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
skip_log_directory=False, expect_error=False, use_backup_dir=True):
skip_log_directory=False, expect_error=False, use_backup_dir=True, daemonize=False):
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это будет раз на команду задаваться или на весь тестовый прогон?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Раз на команду, нужно для того чтобы мочь запустить команду в фоновом режиме. В моем случае чтобы запустить пробэкап с опцией fuse в фоне.

Run pg_probackup
backup_dir: target directory for making backup
Expand Down Expand Up @@ -118,11 +146,14 @@ def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
logging.warning("pg_probackup gdb suspended, waiting gdb connection on localhost:{0}".format(gdb_port))

start_time = time.time()
self.test_class.output = subprocess.check_output(
cmdline,
stderr=subprocess.STDOUT,
env=env
).decode('utf-8', errors='replace')
if daemonize:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

часть в daemonize можно вынести в функцию например такую form_daemon_process

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сделаю, разумно

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поправлено

return self.form_daemon_process(cmdline, env)
else:
self.test_class.output = subprocess.check_output(
cmdline,
stderr=subprocess.STDOUT,
env=env
).decode('utf-8', errors='replace')
end_time = time.time()
self.execution_time = end_time - start_time

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy