]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Use weakrefs instead of __del__ in reference cycle test.
authorBen Darnell <ben@bendarnell.com>
Sun, 28 Apr 2013 22:17:15 +0000 (18:17 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 28 Apr 2013 22:17:15 +0000 (18:17 -0400)
This avoids an awkward and otherwise meaningless use of Task(None).

tornado/test/gen_test.py

index 27c10eefdba64aae17315cf069a75939d3beae2f..a1e09a1330b865c62ade9f324a9ff125c9c66a2d 100644 (file)
@@ -6,6 +6,7 @@ import sys
 import textwrap
 import time
 import platform
+import weakref
 
 from tornado.concurrent import return_future
 from tornado.escape import url_escape
@@ -493,21 +494,21 @@ class GenEngineTest(AsyncTestCase):
 
     @skipNotCPython
     def test_task_refcounting(self):
-        # Task with arguments on CPython should be released immediately after
-        # engine stop. And should not be delayed to garbage collection.
-        class Task(gen.Task):
-            "Task class which count self instances release."
-            released = 0
-            def __del__(self):
-                type(self).released += 1
-
+        # On CPython, tasks and their arguments should be released immediately
+        # without waiting for garbage collection.
         @gen.engine
         def f():
-            yield Task(self.io_loop.add_callback, arg=Task(None))
+            class Foo(object): pass
+            arg = Foo()
+            self.arg_ref = weakref.ref(arg)
+            task = gen.Task(self.io_loop.add_callback, arg=arg)
+            self.task_ref = weakref.ref(task)
+            yield task
             self.stop()
 
         self.run_gen(f)
-        self.assertEqual(Task.released, 2)
+        self.assertIs(self.arg_ref(), None)
+        self.assertIs(self.task_ref(), None)
 
 
 class GenCoroutineTest(AsyncTestCase):