Skip to content

tests/library/harness: get rid of warnings on un-closed files #15274

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

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions ydb/tests/library/harness/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(
stderr_file="/dev/null",
stderr_on_error_lines=0,
core_pattern=None,
templog_file=None
):
self.__cwd = cwd
self.__timeout = timeout
Expand All @@ -73,6 +74,7 @@ def __init__(
self.logger = logger.getChild(self.__class__.__name__)
self.__stdout_file = open(stdout_file, mode='wb')
self.__stderr_file = open(stderr_file, mode='wb')
self.__templog_file = templog_file

@property
def daemon(self):
Expand All @@ -92,6 +94,12 @@ def stderr_file_name(self):
else:
return None

def __del__(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай лучше в stop засунем? Выглядит так, что вызов stop обязателен в любом случае, а вот del вызывается менее детерминированно

Copy link
Collaborator Author

@ijon ijon Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я сначала и вставил это в stop(), но оказалось, что есть тесты (около 45, см. первую сборку), в сценариях которых нужно останавливать ноды и запускать снова, объект Daemon при этом не пересоздаётся, -- то есть вызывается stop(), потом start(), и Daemon должен запуститься на тех же файлах, что он открывал в конструкторе.

Тут либо отдельный явный метод подчистки делать (не деструктор, но и не stop или kill) и найти место, где его правильно вызвать. Либо закрывать и открывать файлы заново не в конструкторе, а в stop и start. И возможно получить разные файлы для разных вызовов start (может хорошо, а может быть и неудобно).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы файлы просто с append бы открывал, и пусть пишут свой вывод в конец -- может это решит проблему?

self.__stdout_file.close()
self.__stderr_file.close()
if self.__templog_file is not None:
self.__templog_file.close()

def is_alive(self):
return self.__daemon is not None and self.__daemon.running

Expand Down
5 changes: 3 additions & 2 deletions ydb/tests/library/harness/kikimr_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ def __init__(self, node_id, config_path, port_allocator, cluster_name, configura
)

if configurator.use_log_files:
self.__log_file = tempfile.NamedTemporaryFile(dir=self.__working_dir, prefix="logfile_", suffix=".log", delete=False)
self.__log_file = tempfile.NamedTemporaryFile(dir=self.__working_dir, prefix="logfile_", suffix=".log", delete=False, delete_on_close=False)
kwargs = {
"stdout_file": os.path.join(self.__working_dir, "stdout"),
"stderr_file": os.path.join(self.__working_dir, "stderr")
"stderr_file": os.path.join(self.__working_dir, "stderr"),
"templog_file": self.__log_file,
}
else:
self.__log_file = None
Expand Down
Loading