From b58de151397c3a85002430c34b0dd1b400cede23 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sun, 20 Jul 2008 06:32:54 +0000 Subject: [PATCH] Fixed #7339 -- Added manual calls to the garbage collector. This is required for PyPy and Jython; these implementations don't use reference counting, so you can't rely on __del__ being run immediately after del is called. Thanks to Maciej Fijalkowski (fijal) and Leo Soto. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8004 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- .../dispatch/tests/test_dispatcher.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/regressiontests/dispatch/tests/test_dispatcher.py b/tests/regressiontests/dispatch/tests/test_dispatcher.py index 0bc99a1505..f34173972d 100644 --- a/tests/regressiontests/dispatch/tests/test_dispatcher.py +++ b/tests/regressiontests/dispatch/tests/test_dispatcher.py @@ -2,6 +2,18 @@ from django.dispatch.dispatcher import * from django.dispatch import dispatcher, robust import unittest import copy +import sys +import gc + +if sys.platform.startswith('java'): + def garbage_collect(): + """Run the garbage collector and wait a bit to let it do his work""" + import time + gc.collect() + time.sleep(0.1) +else: + def garbage_collect(): + gc.collect() def x(a): return a @@ -21,6 +33,7 @@ class DispatcherTests(unittest.TestCase): def setUp(self): # track the initial state, since it's possible that others have bleed receivers in + garbage_collect() self.sendersBack = copy.copy(dispatcher.sendersBack) self.connections = copy.copy(dispatcher.connections) self.senders = copy.copy(dispatcher.senders) @@ -86,6 +99,7 @@ class DispatcherTests(unittest.TestCase): connect(a.a, signal, b) expected = [] del a + garbage_collect() result = send('this',b, a=b) self.assertEqual(result, expected) self.assertEqual(list(getAllReceivers(b,signal)), []) @@ -101,6 +115,7 @@ class DispatcherTests(unittest.TestCase): connect(a, signal, b) expected = [] del a + garbage_collect() result = send('this',b, a=b) self.assertEqual(result, expected) self.assertEqual(list(getAllReceivers(b,signal)), []) @@ -123,6 +138,7 @@ class DispatcherTests(unittest.TestCase): del a del b del result + garbage_collect() self._testIsClean() def testRobust(self): @@ -141,4 +157,4 @@ def getSuite(): return unittest.makeSuite(DispatcherTests,'test') if __name__ == "__main__": - unittest.main () + unittest.main()