Skip to content

gh-102402: Fix logging test_relativeCreated_has_higher_precision() leak - #117985

Merged
vstinner merged 2 commits into
python:mainfrom
vstinner:fix_test_logging_leak
Apr 18, 2024
Merged

gh-102402: Fix logging test_relativeCreated_has_higher_precision() leak#117985
vstinner merged 2 commits into
python:mainfrom
vstinner:fix_test_logging_leak

Conversation

@vstinner

@vstinnervstinner commented Apr 17, 2024

Copy link
Copy Markdown
Member

Fix a reference leak in test_relativeCreated_has_higher_precision() of test_logging: don't reimport the logging the logging module.

…n() leak
Fix a reference leak in test_relativeCreated_has_higher_precision()
of test_logging: don't reimport the logging the logging module.
@vstinner

Copy link
Copy Markdown
MemberAuthor

@vsajip@serhiy-storchaka: Would you mind to review my fix?

@serhiy-storchakaserhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like an intermediate version of this test. I did not like it. It relies on implementation details -- that _startTime exists, that it is initialize with the time as nanoseconds, and that there are no other variables that depend on the starting time. If we rely so much on these details, we could simply not add this test at first place.

I tried to re-import a new logging module with its submodules. It seems not working too. Perhaps the only solution is to run a script which patches time_ns() before the first import of logging.

It is still unsolved mistery why re-importing the logging module leaks.

@vstinner

Copy link
Copy Markdown
MemberAuthor

It relies on implementation details -- that _startTime exists, that it is initialize with the time as nanoseconds, and that there are no other variables that depend on the starting time.

The test can be marked as @cpython_only if needed. The test already makes the assumption that the logging module uses time.time_ns(). What if it uses time.time() on PyPy, or what if it uses time.monotonic_ns(), etc.?

Creating a new module instance is causing too much trouble. For example, it calls os.register_at_fork() which cannot be unregistered, unless the function is mocked as well. That's just an example: commenting this code is not enough to fix the leak.

@vstinner

Copy link
Copy Markdown
MemberAuthor

The test can be marked as @cpython_only if needed.

Done.

@vstinner
vstinner merged commit 8f25cc9 into python:mainApr 18, 2024
@vstinner
vstinner deleted the fix_test_logging_leak branch April 18, 2024 17:01
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip newstestsTests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@vstinner@serhiy-storchaka