diff options
| author | Jason Madden <jamadden@gmail.com> | 2020-09-28 06:09:42 -0500 |
|---|---|---|
| committer | Jason Madden <jamadden@gmail.com> | 2020-09-28 06:09:42 -0500 |
| commit | b749fc0f17ee628b9ef7bb8afd14b6bf51414bff (patch) | |
| tree | 3890f864d5f7691710160d49f97c70ac376f3a6b /src/zope/interface/tests | |
| parent | 255db9d3c0ea7a5016e3c87644c23fca6eda9a7d (diff) | |
| download | zope-interface-b749fc0f17ee628b9ef7bb8afd14b6bf51414bff.tar.gz | |
C optimizations: Spec_clear and Spec_traverse need to include Spec->_bases
Previously they did not, leading to a reference leak of a tuple.
Fixes #216
Diffstat (limited to 'src/zope/interface/tests')
| -rw-r--r-- | src/zope/interface/tests/test_declarations.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/zope/interface/tests/test_declarations.py b/src/zope/interface/tests/test_declarations.py index c8678b5..9ef192a 100644 --- a/src/zope/interface/tests/test_declarations.py +++ b/src/zope/interface/tests/test_declarations.py @@ -1078,6 +1078,35 @@ class Test_implementer(Test_classImplements): self.assertIsNone(spec.inherit,) self.assertIs(foo.__implemented__, spec) # pylint:disable=no-member + def test_does_not_leak_on_unique_classes(self): + # Make sure nothing is hanging on to the class or Implements + # object after they go out of scope. There was briefly a bug + # in 5.x that caused SpecificationBase._bases (in C) to not be + # traversed or cleared. + # https://github.com/zopefoundation/zope.interface/issues/216 + import gc + from zope.interface.interface import InterfaceClass + IFoo = InterfaceClass('IFoo') + + begin_count = len(gc.get_objects()) + + for _ in range(1900): + class TestClass(object): + pass + + self._callFUT(TestClass, IFoo) + + gc.collect() + + end_count = len(gc.get_objects()) + + # How many new objects might still be around? In all currently + # tested interpreters, there aren't any, so our counts should + # match exactly. When the bug existed, in a steady state, the loop + # would grow by two objects each iteration + fudge_factor = 0 + self.assertLessEqual(end_count, begin_count + fudge_factor) + class Test_implementer_only(Test_classImplementsOnly): |
