[Jython-checkins] jython: Fix flaky tests in test_weakref and test_weakset

jim.baker jython-checkins at python.org
Tue Dec 9 04:41:23 CET 2014


https://hg.python.org/jython/rev/8833d46c7dd6
changeset:   7438:8833d46c7dd6
user:        Jim Baker <jim.baker at rackspace.com>
date:        Mon Dec 08 20:41:17 2014 -0700
summary:
  Fix flaky tests in test_weakref and test_weakset

Weak reference callbacks are called by a separate reaper thread,
therefore tests have to be sensitive to possible races. Although
arguably making this more robust by appropriate interleaving of
gc.collect() and time.sleep() is not good enough, these tests are as
good as we can make without making them more JVM dependent.

files:
  Lib/test/test_weakref.py |  2 +-
  Lib/test/test_weakset.py |  2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)


diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -153,7 +153,7 @@
         o2 = C()
         ref3 = weakref.proxy(o2)
         del o2
-        gc.collect()
+        extra_collect()
         self.assertRaises(weakref.ReferenceError, bool, ref3)
 
         self.assertTrue(self.cbcalled == 2)
diff --git a/Lib/test/test_weakset.py b/Lib/test/test_weakset.py
--- a/Lib/test/test_weakset.py
+++ b/Lib/test/test_weakset.py
@@ -391,7 +391,7 @@
         # We have removed either the first consumed items, or another one
         self.assertIn(len(list(it)), [len(items), len(items) - 1])
         del it
-        gc.collect()
+        extra_collect()
         # The removal has been committed
         self.assertEqual(len(s), len(items))
 

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


More information about the Jython-checkins mailing list