summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_gc.py
diff options
context:
space:
mode:
authorHugo van Kemenade <1324225+hugovk@users.noreply.github.com>2024-11-19 09:25:09 (GMT)
committerGitHub <noreply@github.com>2024-11-19 09:25:09 (GMT)
commit899fdb213db6c5881c5f9c6760ead6fd713d2070 (patch)
treec4e291504c73e8055d02176551beeb39ab47e6ad /Lib/test/test_gc.py
parent84f07c3a4cbcfe488ccfb4030571be0bc4de7e45 (diff)
downloadcpython-899fdb213db6c5881c5f9c6760ead6fd713d2070.zip
cpython-899fdb213db6c5881c5f9c6760ead6fd713d2070.tar.gz
cpython-899fdb213db6c5881c5f9c6760ead6fd713d2070.tar.bz2
Revert "GH-126491: GC: Mark objects reachable from roots before doing cycle collection (GH-126502)" (#126983)
Diffstat (limited to 'Lib/test/test_gc.py')
-rw-r--r--Lib/test/test_gc.py33
1 files changed, 19 insertions, 14 deletions
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py
index e02ec7c..0372815 100644
--- a/Lib/test/test_gc.py
+++ b/Lib/test/test_gc.py
@@ -31,11 +31,6 @@ except ImportError:
return C
ContainerNoGC = None
-try:
- import _testinternalcapi
-except ImportError:
- _testinternalcapi = None
-
### Support code
###############################################################################
@@ -1135,7 +1130,6 @@ class IncrementalGCTests(unittest.TestCase):
def tearDown(self):
gc.disable()
- @unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
@requires_gil_enabled("Free threading does not support incremental GC")
# Use small increments to emulate longer running process in a shorter time
@gc_threshold(200, 10)
@@ -1161,18 +1155,32 @@ class IncrementalGCTests(unittest.TestCase):
return head
head = make_ll(1000)
+ count = 1000
+
+ # There will be some objects we aren't counting,
+ # e.g. the gc stats dicts. This test checks
+ # that the counts don't grow, so we try to
+ # correct for the uncounted objects
+ # This is just an estimate.
+ CORRECTION = 20
enabled = gc.isenabled()
gc.enable()
olds = []
- initial_heap_size = _testinternalcapi.get_heap_size()
for i in range(20_000):
newhead = make_ll(20)
+ count += 20
newhead.surprise = head
olds.append(newhead)
if len(olds) == 20:
- new_objects = _testinternalcapi.get_heap_size() - initial_heap_size
- self.assertLess(new_objects, 25_000)
+ stats = gc.get_stats()
+ young = stats[0]
+ incremental = stats[1]
+ old = stats[2]
+ collected = young['collected'] + incremental['collected'] + old['collected']
+ count += CORRECTION
+ live = count - collected
+ self.assertLess(live, 25000)
del olds[:]
if not enabled:
gc.disable()
@@ -1314,8 +1322,7 @@ class GCCallbackTests(unittest.TestCase):
from test.support import gc_collect, SuppressCrashReport
a = [1, 2, 3]
- b = [a, a]
- a.append(b)
+ b = [a]
# Avoid coredump when Py_FatalError() calls abort()
SuppressCrashReport().__enter__()
@@ -1325,8 +1332,6 @@ class GCCallbackTests(unittest.TestCase):
# (to avoid deallocating it):
import ctypes
ctypes.pythonapi.Py_DecRef(ctypes.py_object(a))
- del a
- del b
# The garbage collector should now have a fatal error
# when it reaches the broken object
@@ -1355,7 +1360,7 @@ class GCCallbackTests(unittest.TestCase):
self.assertRegex(stderr,
br'object type name: list')
self.assertRegex(stderr,
- br'object repr : \[1, 2, 3, \[\[...\], \[...\]\]\]')
+ br'object repr : \[1, 2, 3\]')
class GCTogglingTests(unittest.TestCase):