]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-139951: Test on GC collection disabled if threshold is zero (GH-140304)
authorMikhail Efimov <efimov.mikhail@gmail.com>
Mon, 20 Oct 2025 10:45:07 +0000 (13:45 +0300)
committerGitHub <noreply@github.com>
Mon, 20 Oct 2025 10:45:07 +0000 (11:45 +0100)
Lib/test/test_gc.py

index 4328909053465eaf2dc0a75c61de9ed6145be510..70d9d009fa8bfdfb80b62717ff68d26ea206eba6 100644 (file)
@@ -1559,6 +1559,20 @@ class GCTogglingTests(unittest.TestCase):
         finally:
             gc.enable()
 
+    # Ensure that setting *threshold0* to zero disables collection.
+    @gc_threshold(0)
+    def test_threshold_zero(self):
+        junk = []
+        i = 0
+        detector = GC_Detector()
+        while not detector.gc_happened:
+            i += 1
+            if i > 50000:
+                break
+            junk.append([])  # this may eventually trigger gc (if it is enabled)
+
+        self.assertEqual(i, 50001)
+
 
 class PythonFinalizationTests(unittest.TestCase):
     def test_ast_fini(self):