From df3e4cbfe6883b6e1d8f0ddb2a773090fd12f189 Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Wed, 4 Dec 2024 12:23:52 +0100 Subject: [PATCH 1/2] Output logs for integration tests, add TeePopen.terminate --- tests/ci/integration_tests_runner.py | 17 ++++++++--------- tests/ci/tee_popen.py | 5 ++++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/ci/integration_tests_runner.py b/tests/ci/integration_tests_runner.py index 35f7309fbe2..612be7f8f36 100755 --- a/tests/ci/integration_tests_runner.py +++ b/tests/ci/integration_tests_runner.py @@ -655,13 +655,12 @@ class ClickhouseIntegrationTestsRunner: log_basename = test_group_str + "_" + str(i) + ".log" log_path = os.path.join(self.repo_path, "tests/integration", log_basename) - with open(log_path, "w", encoding="utf-8") as log: - logging.info("Executing cmd: %s", cmd) - # ignore retcode, since it meaningful due to pipe to tee - with subprocess.Popen(cmd, shell=True, stderr=log, stdout=log) as proc: - global runner_subprocess # pylint:disable=global-statement - runner_subprocess = proc - proc.wait() + logging.info("Executing cmd: %s", cmd) + # ignore retcode, since it meaningful due to pipe to tee + with TeePopen(cmd, log_path) as proc: + global runner_subprocess # pylint:disable=global-statement + runner_subprocess = proc + proc.wait() extra_logs_names = [log_basename] log_result_path = os.path.join( @@ -1089,7 +1088,7 @@ def run(): timeout_expired = False -runner_subprocess = None # type:Optional[subprocess.Popen] +runner_subprocess = None # type:Optional[TeePopen] def handle_sigterm(signum, _frame): @@ -1098,7 +1097,7 @@ def handle_sigterm(signum, _frame): global timeout_expired # pylint:disable=global-statement timeout_expired = True if runner_subprocess: - runner_subprocess.send_signal(signal.SIGTERM) + runner_subprocess.terminate() if __name__ == "__main__": diff --git a/tests/ci/tee_popen.py b/tests/ci/tee_popen.py index e5802d006f8..26d1d4b9c00 100644 --- a/tests/ci/tee_popen.py +++ b/tests/ci/tee_popen.py @@ -44,9 +44,12 @@ class TeePopen: self.timeout, ) self.send_signal(signal.SIGTERM) + self.timeout_exceeded = True + self.terminate() + + def terminate(self) -> None: time_wait = 0 self.terminated_by_sigterm = True - self.timeout_exceeded = True while self.process.poll() is None and time_wait < 100: print("wait...") wait = 5 From 62f2eda0f13331935732ff1c5bb69da0a9eb14b0 Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Wed, 4 Dec 2024 13:08:58 +0100 Subject: [PATCH 2/2] Fix TeePopen.terminate by moving send_signal there --- tests/ci/tee_popen.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/ci/tee_popen.py b/tests/ci/tee_popen.py index 26d1d4b9c00..e9e00704f9a 100644 --- a/tests/ci/tee_popen.py +++ b/tests/ci/tee_popen.py @@ -43,25 +43,24 @@ class TeePopen: self.process.pid, self.timeout, ) - self.send_signal(signal.SIGTERM) self.timeout_exceeded = True self.terminate() - def terminate(self) -> None: + def terminate(self, wait_before_kill: int = 100) -> None: time_wait = 0 + time_sleep = 5 self.terminated_by_sigterm = True - while self.process.poll() is None and time_wait < 100: - print("wait...") - wait = 5 - sleep(wait) - time_wait += wait + self.send_signal(signal.SIGTERM) + while self.process.poll() is None and time_wait < wait_before_kill: + logging.warning("Wait the process %s to terminate", self.process.pid) + sleep(time_sleep) + time_wait += time_sleep + + self.terminated_by_sigkill = True while self.process.poll() is None: - logging.error( - "Process is still running. Send SIGKILL", - ) + logging.error("Process is still running. Send SIGKILL") self.send_signal(signal.SIGKILL) - self.terminated_by_sigkill = True - sleep(5) + sleep(time_sleep) def __enter__(self) -> "TeePopen": self.process = Popen(