@@ -397,6 +397,49 @@ def test_collect_generations(self):
397397 self .assertEqual ((e , f ), (0 , 1 ))
398398 self .assertEqual ((h , i ), (0 , 0 ))
399399
400+ def test_adaptive_threshold_env_var (self ):
401+ code = textwrap .dedent ("""
402+ import gc
403+
404+ start = gc.get_threshold()
405+ keep = []
406+ for _ in range(8):
407+ keep.extend([] for _ in range(1000))
408+ gc.collect(0)
409+ end = gc.get_threshold()
410+
411+ assert start == (700, 10, 10), start
412+ assert end[0] > start[0], end
413+ assert end[1:] == start[1:], end
414+ """ )
415+ assert_python_ok ("-c" , code , PYTHON_GC_ADAPTIVE = "1" )
416+
417+ def test_adaptive_threshold_env_var_ignored_by_E (self ):
418+ code = textwrap .dedent ("""
419+ import gc
420+
421+ keep = []
422+ for _ in range(8):
423+ keep.extend([] for _ in range(1000))
424+ gc.collect(0)
425+ assert gc.get_threshold() == (700, 10, 10)
426+ """ )
427+ assert_python_ok ("-E" , "-c" , code , PYTHON_GC_ADAPTIVE = "1" )
428+
429+ def test_adaptive_max_threshold_env_var (self ):
430+ code = textwrap .dedent ("""
431+ import gc
432+
433+ keep = []
434+ for _ in range(8):
435+ keep.extend([] for _ in range(1000))
436+ gc.collect(0)
437+ assert gc.get_threshold() == (900, 10, 10), gc.get_threshold()
438+ """ )
439+ assert_python_ok ("-c" , code ,
440+ PYTHON_GC_ADAPTIVE = "1" ,
441+ PYTHON_GC_ADAPTIVE_MAX_THRESHOLD0 = "900" )
442+
400443 def test_trashcan (self ):
401444 class Ouch :
402445 n = 0
0 commit comments