[Jython-checkins] jython: Re-enable memory leak test on type <-> class mapping

jim.baker jython-checkins at python.org
Sat Dec 13 03:35:25 CET 2014


https://hg.python.org/jython/rev/fe4e370f23c2
changeset:   7447:fe4e370f23c2
user:        Jim Baker <jim.baker at rackspace.com>
date:        Fri Dec 12 19:35:19 2014 -0700
summary:
  Re-enable memory leak test on type <-> class mapping

Taking the len (or size()) of weak maps in Google Guava is eventually
consistent, which is not terribly useful for our testing.  Instead we
measure this by taking the length of its keys (or other iterable).

files:
  Lib/test/test_jy_internals.py |  26 +++++++---------------
  1 files changed, 9 insertions(+), 17 deletions(-)


diff --git a/Lib/test/test_jy_internals.py b/Lib/test/test_jy_internals.py
--- a/Lib/test/test_jy_internals.py
+++ b/Lib/test/test_jy_internals.py
@@ -1,7 +1,6 @@
 """
  test some jython internals
 """
-import gc
 import unittest
 import time
 from test import test_support
@@ -18,7 +17,6 @@
 
 class MemoryLeakTests(unittest.TestCase):
 
-    @unittest.skip("FIXME: broken in 2.7.")
     def test_class_to_test_weakness(self):
         # regrtest for bug 1522, adapted from test code submitted by Matt Brinkley
 
@@ -28,16 +26,6 @@
         # `type`!)
         class_to_type_map = getField(type, 'class_to_type').get(None)
 
-        def make_clean():
-            # gc a few times just to be really sure, since in this
-            # case we don't really care if it takes a few cycles of GC
-            # for the garbage to be reached
-            gc.collect()
-            time.sleep(0.1)
-            gc.collect()
-            time.sleep(0.5)
-            gc.collect()
-
         def create_proxies():
             pi = PythonInterpreter()
             pi.exec("""
@@ -51,16 +39,20 @@
 
 Dog().bark()
 """)
-            make_clean()
-    
         # get to steady state first, then verify we don't create new proxies
         for i in xrange(2):
             create_proxies()
-        start_size = class_to_type_map.size()
+        # Ensure the reaper thread can run and clear out weak refs, so
+        # use this supporting function
+        test_support.gc_collect()
+        # Given that taking the len (or size()) of Guava weak maps is
+        # eventually consistent, we should instead take a len of its
+        # keys.
+        start_size = len(list(class_to_type_map))
         for i in xrange(5):
             create_proxies()
-        make_clean()
-        self.assertEqual(start_size, class_to_type_map.size())
+        test_support.gc_collect()
+        self.assertEqual(start_size, len(list(class_to_type_map)))
 
 
 class WeakIdentityMapTests(unittest.TestCase):

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list