mirror of
https://github.com/neondatabase/neon.git
synced 2025-12-23 06:09:59 +00:00
test: include cmdline in captured output (#5977)
aiming for faster to understand a bunch of `.stdout` and `.stderr` files, see example echo_1.stdout differences: ``` +# echo foobar abbacd + foobar abbacd ``` it can be disabled and is disabled in this PR for some tests; use `pg_bin.run_capture(..., with_command_header=False)` for that. as a bonus this cleans up the echoed newlines from s3_scrubber output which are also saved to file but echoed to test log. Co-authored-by: Alexander Bayandin <alexander@neon.tech>
This commit is contained in:
@@ -49,7 +49,8 @@ def subprocess_capture(
|
||||
echo_stdout=False,
|
||||
capture_stdout=False,
|
||||
timeout=None,
|
||||
**kwargs: Any,
|
||||
with_command_header=True,
|
||||
**popen_kwargs: Any,
|
||||
) -> Tuple[str, Optional[str], int]:
|
||||
"""Run a process and bifurcate its output to files and the `log` logger
|
||||
|
||||
@@ -86,13 +87,23 @@ def subprocess_capture(
|
||||
self.captured = ""
|
||||
|
||||
def run(self):
|
||||
first = with_command_header
|
||||
for line in self.in_file:
|
||||
if first:
|
||||
# do this only after receiving any input so that we can
|
||||
# keep deleting empty files, or leave it out completly if
|
||||
# it was unwanted (using the file as input later for example)
|
||||
first = False
|
||||
# prefix the files with the command line so that we can
|
||||
# later understand which file is for what command
|
||||
self.out_file.write((f"# {' '.join(cmd)}\n\n").encode("utf-8"))
|
||||
|
||||
# Only bother decoding if we are going to do something more than stream to a file
|
||||
if self.echo or self.capture:
|
||||
string = line.decode(encoding="utf-8", errors="replace")
|
||||
|
||||
if self.echo:
|
||||
log.info(string)
|
||||
log.info(string.strip())
|
||||
|
||||
if self.capture:
|
||||
self.captured += string
|
||||
@@ -107,7 +118,7 @@ def subprocess_capture(
|
||||
|
||||
p = subprocess.Popen(
|
||||
cmd,
|
||||
**kwargs,
|
||||
**popen_kwargs,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user