-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-87298: Add tests for find_in_strong_cache() bug in _zoneinfo #24829
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
gh-87298: Add tests for find_in_strong_cache() bug in _zoneinfo #24829
Conversation
Co-Authored-By: Paul Ganssle <[email protected]>
7c640db
to
1f7a1fa
Compare
This PR is stale because it has been open for 30 days with no activity. |
Serhiy, since you merged #24450, maybe you can review the tests? |
Thanks @ZackerySpytz for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
…pythonGH-24829) (cherry picked from commit 12ce16b) Co-authored-by: Zackery Spytz <[email protected]> Co-authored-by: Paul Ganssle <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
GH-136181 is a backport of this pull request to the 3.14 branch. |
…pythonGH-24829) (cherry picked from commit 12ce16b) Co-authored-by: Zackery Spytz <[email protected]> Co-authored-by: Paul Ganssle <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
GH-136182 is a backport of this pull request to the 3.13 branch. |
@@ -1507,6 +1530,26 @@ def test_clear_cache_two_keys(self): | |||
self.assertIsNot(dub0, dub1) | |||
self.assertIs(tok0, tok1) | |||
|
|||
def test_clear_cache_refleak(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently I wrote this function 4 years ago, but coming back to it now it is opaque as heck, so we should probably describe what this test is about.
def test_clear_cache_refleak(self): | |
def test_clear_cache_refleak(self): | |
# bpo-43132: The portion of the C implementation of ZoneInfo that | |
# ejects specific keys from the strong cache (i.e. the LRU cache) was | |
# leaking references if comparing to the key object failed; because the | |
# strong cache is not currently implemented for subclasses, this test | |
# only really applies to the C implementation of the ZoneInfo class. |
self.klass(key) | ||
key.allow_comparisons = False | ||
try: | ||
# Note: This is try/except rather than assertRaises because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize that I wrote this function, but it kind of bothers me that this can silently become a no-op (and in fact this is silently a no-op for all subclasses ZoneInfo
). I think that the only way around it is fairly annoying if we want to allow tests to run in parallel, which is that we would need to acquire a lock around anything that deals with the cache.
__hash__ = str.__hash__ | ||
|
||
key = Stringy("America/Los_Angeles") | ||
self.klass(key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To increase the chance that this actually works:
self.klass(key) | |
self.klass.clear_cache(only_keys="America/Los_Angeles") | |
self.klass(key) |
@@ -1507,6 +1530,26 @@ def test_clear_cache_two_keys(self): | |||
self.assertIsNot(dub0, dub1) | |||
self.assertIs(tok0, tok1) | |||
|
|||
def test_clear_cache_refleak(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may also want to skip this test if self.klass
is not exactly the C implementation of ZoneInfo
, since otherwise it's a no-op.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Oof, missed the window for this by 12 minutes. |
GH-24829) (GH-136182) (cherry picked from commit 12ce16b) Co-authored-by: Zackery Spytz <[email protected]> Co-authored-by: Paul Ganssle <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
GH-24829) (GH-136181) (cherry picked from commit 12ce16b) Co-authored-by: Zackery Spytz <[email protected]> Co-authored-by: Paul Ganssle <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
Sorry, the PR was already on auto-merge. |
Co-Authored-By: Paul Ganssle [email protected]
https://bugs.python.org/issue43132