From 14a809d91ba9892350abf9aa44ddf3948f7e2c9d Mon Sep 17 00:00:00 2001 From: Lukasz Sojka Date: Wed, 18 Sep 2024 13:58:50 +0200 Subject: [PATCH] fix(wait_for_log_lines): fix saturating cpu when waiting for log lines We missed waiting time before recreating iterator. This causes unnecessary high cpu utilization. refs: https://github.com/scylladb/scylla-cluster-tests/issues/8720 (cherry picked from commit 092da0164ae2770f7654cec4c5a69defa0893c9f) --- sdcm/wait.py | 2 ++ unit_tests/test_wait.py | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sdcm/wait.py b/sdcm/wait.py index 5a84816562..afe3aba6e9 100644 --- a/sdcm/wait.py +++ b/sdcm/wait.py @@ -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) diff --git a/unit_tests/test_wait.py b/unit_tests/test_wait.py index e72e89afdf..826bafc44d 100644 --- a/unit_tests/test_wait.py +++ b/unit_tests/test_wait.py @@ -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): @@ -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): @@ -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') @@ -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()) @@ -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()