Skip to content

Commit

Permalink
fix(wait_for_log_lines): fix saturating cpu when waiting for log lines
Browse files Browse the repository at this point in the history
We missed waiting time before recreating iterator. This causes
unnecessary high cpu utilization.

refs: #8720
(cherry picked from commit 092da01)
  • Loading branch information
soyacz committed Sep 23, 2024
1 parent 85d384e commit 3d6dd6f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions sdcm/wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,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(
f"timeout occurred while waiting for start log line ({start_line_patterns} on node: {node.name}")
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(
f"timeout occurred while waiting for end log line ({end_line_patterns} on node: {node.name}")
8 changes: 4 additions & 4 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,6 +254,6 @@ 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())

0 comments on commit 3d6dd6f

Please sign in to comment.