Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(logfiles): handle incomplete lines without preserving endings #2901

Merged
merged 1 commit into from
Feb 7, 2025
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
20 changes: 9 additions & 11 deletions cardano_node_tests/utils/logfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ def _search_log_lines( # noqa: C901
# Prepend any leftover from the last chunk
if incomplete_line:
chunk = incomplete_line + chunk
lines = chunk.splitlines(keepends=True) # Preserve line endings
lines = chunk.splitlines(keepends=False)

# Check if the last line is incomplete
incomplete_line = lines.pop() if not lines[-1].endswith(("\n", "\r")) else ""
# Handle incomplete lines at the end of the chunk
incomplete_line = lines.pop() if chunk[-1] not in "\n\r" else ""

for line in lines:
look_back_buf.append(line)
Expand Down Expand Up @@ -318,10 +318,10 @@ def find_msgs_in_logs(
# Prepend any leftover from the last chunk
if incomplete_line:
chunk = incomplete_line + chunk
lines = chunk.splitlines(keepends=True) # Preserve line endings
lines = chunk.splitlines(keepends=False)

# Check if the last line is incomplete
incomplete_line = lines.pop() if not lines[-1].endswith(("\n", "\r")) else ""
# Handle incomplete lines at the end of the chunk
incomplete_line = lines.pop() if chunk[-1] not in "\n\r" else ""

for line in lines:
if regex_comp.search(line):
Expand Down Expand Up @@ -373,12 +373,10 @@ def check_msgs_presence_in_logs( # noqa: C901
# Prepend any leftover from the last chunk
if incomplete_line:
chunk = incomplete_line + chunk
lines = chunk.splitlines(keepends=True) # Preserve line endings
lines = chunk.splitlines(keepends=False)

# Check if the last line is incomplete
incomplete_line = (
lines.pop() if not lines[-1].endswith(("\n", "\r")) else ""
)
# Handle incomplete lines at the end of the chunk
incomplete_line = lines.pop() if chunk[-1] not in "\n\r" else ""

for line in lines:
if regex_comp.search(line):
Expand Down
Loading