Merge pull request #72793 from ClickHouse/integration-tests-output

Output logs for integration tests, add TeePopen.terminate
This commit is contained in:
Mikhail f. Shiryaev 2024-12-04 21:16:09 +00:00 committed by GitHub
commit 2f3f5dbe0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 22 deletions

View File

@ -655,10 +655,9 @@ class ClickhouseIntegrationTestsRunner:
log_basename = test_group_str + "_" + str(i) + ".log" log_basename = test_group_str + "_" + str(i) + ".log"
log_path = os.path.join(self.repo_path, "tests/integration", log_basename) 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) logging.info("Executing cmd: %s", cmd)
# ignore retcode, since it meaningful due to pipe to tee # ignore retcode, since it meaningful due to pipe to tee
with subprocess.Popen(cmd, shell=True, stderr=log, stdout=log) as proc: with TeePopen(cmd, log_path) as proc:
global runner_subprocess # pylint:disable=global-statement global runner_subprocess # pylint:disable=global-statement
runner_subprocess = proc runner_subprocess = proc
proc.wait() proc.wait()
@ -1089,7 +1088,7 @@ def run():
timeout_expired = False timeout_expired = False
runner_subprocess = None # type:Optional[subprocess.Popen] runner_subprocess = None # type:Optional[TeePopen]
def handle_sigterm(signum, _frame): def handle_sigterm(signum, _frame):
@ -1098,7 +1097,7 @@ def handle_sigterm(signum, _frame):
global timeout_expired # pylint:disable=global-statement global timeout_expired # pylint:disable=global-statement
timeout_expired = True timeout_expired = True
if runner_subprocess: if runner_subprocess:
runner_subprocess.send_signal(signal.SIGTERM) runner_subprocess.terminate()
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -43,22 +43,24 @@ class TeePopen:
self.process.pid, self.process.pid,
self.timeout, self.timeout,
) )
self.send_signal(signal.SIGTERM)
time_wait = 0
self.terminated_by_sigterm = True
self.timeout_exceeded = True self.timeout_exceeded = True
while self.process.poll() is None and time_wait < 100: self.terminate()
print("wait...")
wait = 5 def terminate(self, wait_before_kill: int = 100) -> None:
sleep(wait) time_wait = 0
time_wait += wait time_sleep = 5
while self.process.poll() is None: self.terminated_by_sigterm = True
logging.error( self.send_signal(signal.SIGTERM)
"Process is still running. Send SIGKILL", while self.process.poll() is None and time_wait < wait_before_kill:
) logging.warning("Wait the process %s to terminate", self.process.pid)
self.send_signal(signal.SIGKILL) sleep(time_sleep)
time_wait += time_sleep
self.terminated_by_sigkill = True self.terminated_by_sigkill = True
sleep(5) while self.process.poll() is None:
logging.error("Process is still running. Send SIGKILL")
self.send_signal(signal.SIGKILL)
sleep(time_sleep)
def __enter__(self) -> "TeePopen": def __enter__(self) -> "TeePopen":
self.process = Popen( self.process = Popen(