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

[Backport 2024.2] fix(wait_for_log_lines): fix saturating cpu when waiting for log lines #8811

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions sdcm/wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ def wait_for_log_lines(node, start_line_patterns, end_line_patterns, start_timeo
started = any(start_follower)
while not started and (time.time() - start_time < start_timeout):
started = any(start_follower)
time.sleep(0.1)
if not started:
raise TimeoutError(start_ctx)
LOGGER.debug("Start line patterns %s were found.%s", start_line_patterns, error_msg_ctx)
ended = any(end_follower)
while not ended and (time.time() - start_time < end_timeout):
ended = any(end_follower)
time.sleep(0.1)
if not ended:
raise TimeoutError(end_ctx)
LOGGER.debug("End line patterns %s were found.%s", end_line_patterns, error_msg_ctx)
10 changes: 5 additions & 5 deletions unit_tests/test_wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_wait_for_log_timeout_when_no_start_line(self, tmp_path):
t.daemon = True
file_path.touch()
with pytest.raises(TimeoutError, match="Timeout occurred while waiting for start log line"), \
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.3, end_timeout=1):
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.4, end_timeout=1.2):
t.start()

def test_wait_for_log_timeout_when_no_end_line(self, tmp_path):
Expand All @@ -234,7 +234,7 @@ def test_wait_for_log_timeout_when_no_end_line(self, tmp_path):
t.daemon = True
file_path.touch()
with pytest.raises(TimeoutError, match="Timeout occurred while waiting for end log line"), \
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.1, end_timeout=0.3):
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.5, end_timeout=0.7):
t.start()

def test_wait_for_log_reraises_exception(self, tmp_path):
Expand All @@ -245,7 +245,7 @@ def test_wait_for_log_reraises_exception(self, tmp_path):
t.daemon = True
file_path.touch()
with pytest.raises(ValueError, match="dummy error"), \
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.1, end_timeout=0.3):
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.5, end_timeout=0.7):
t.start()
raise ValueError('dummy error')

Expand All @@ -254,7 +254,7 @@ def test_wait_for_log_reraises_exception_and_timeout_error(self, tmp_path):
node = DummyNode(log_path=file_path)
file_path.touch()
with pytest.raises(TimeoutError, match="Timeout occurred while waiting for start log line") as exc_info, \
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.1, end_timeout=0.3):
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.4, end_timeout=0.7):
raise ValueError('dummy error')
assert "ValueError" in str(exc_info.getrepr())

Expand All @@ -267,5 +267,5 @@ def test_wait_for_log_reraises_timeout_error_with_error_context(self, tmp_path):
file_path.touch()
expected_match = "Timeout occurred while waiting for end log line \['end'\] on node: node_1. Context: Wait end line"
with pytest.raises(TimeoutError, match=expected_match), \
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.1, end_timeout=0.3, error_msg_ctx="Wait end line"):
wait_for_log_lines(node=node, start_line_patterns=["start"], end_line_patterns=["end"], start_timeout=0.4, end_timeout=0.7, error_msg_ctx="Wait end line"):
t.start()
Loading