]> granicus.if.org Git - python/commitdiff
Add Tim's gc boom test to the test suite.
authorJeremy Hylton <jeremy@alum.mit.edu>
Fri, 4 Apr 2003 20:00:04 +0000 (20:00 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Fri, 4 Apr 2003 20:00:04 +0000 (20:00 +0000)
Lib/test/test_gc.py

index 95cea290d91cb5f1c9d5e0bdb53047e806a2c371..f190fa4b0cb71e10419f3cf26d4a90d63cd3eda4 100644 (file)
@@ -253,6 +253,24 @@ def test_trashcan():
             v = {1: v, 2: Ouch()}
     gc.disable()
 
+class C:
+    def __getattr__(self, attr):
+        del self.attr
+        raise AttributeError
+
+def test_boom():
+    a = C()
+    b = C()
+    a.attr = b
+    b.attr = a
+
+    gc.collect()
+    del a, b
+    # the collection will invoke the getattr and decref one of the
+    # object.  so they are deallocated without being reported as
+    # part of a cycle.
+    expect(gc.collect(), 0, "boom")
+
 def test_all():
     gc.collect() # Delete 2nd generation garbage
     run_test("lists", test_list)
@@ -271,6 +289,7 @@ def test_all():
     run_test("__del__ (new class)", test_del_newclass)
     run_test("saveall", test_saveall)
     run_test("trashcan", test_trashcan)
+    run_test("boom", test_boom)
 
 def test():
     if verbose: