Replace all GC.disable with EnvUtil.without_gc

This commit is contained in:
Peter Zhu 2024-09-16 15:29:38 -04:00
parent 82151a8630
commit 0160dafc4c
Notes: git 2024-09-17 14:34:47 +00:00
5 changed files with 98 additions and 113 deletions

View File

@ -244,7 +244,7 @@ class TestObjSpace < Test::Unit::TestCase
def test_trace_object_allocations_start_stop_clear
ObjectSpace.trace_object_allocations_clear # clear object_table to get rid of erroneous detection for obj3
GC.disable # suppress potential object reuse. see [Bug #11271]
EnvUtil.without_gc do # suppress potential object reuse. see [Bug #11271]
begin
ObjectSpace.trace_object_allocations_start
begin
@ -275,8 +275,7 @@ class TestObjSpace < Test::Unit::TestCase
assert_equal(nil, ObjectSpace.allocation_sourcefile(obj1))
assert_equal(nil, ObjectSpace.allocation_sourcefile(obj2))
assert_equal(nil, ObjectSpace.allocation_sourcefile(obj3))
ensure
GC.enable
end
end
def test_trace_object_allocations_gc_stress

View File

@ -40,6 +40,7 @@ class TestGc < Test::Unit::TestCase
end
def test_enable_disable
EnvUtil.without_gc do
GC.enable
assert_equal(false, GC.enable)
assert_equal(false, GC.disable)
@ -48,8 +49,7 @@ class TestGc < Test::Unit::TestCase
assert_nil(GC.start)
assert_equal(true, GC.enable)
assert_equal(false, GC.enable)
ensure
GC.enable
end
end
def test_gc_config_full_mark_by_default
@ -227,12 +227,9 @@ class TestGc < Test::Unit::TestCase
GC.stat(stat)
GC::INTERNAL_CONSTANTS[:SIZE_POOL_COUNT].times do |i|
begin
reenable_gc = !GC.disable
EnvUtil.without_gc do
GC.stat_heap(i, stat_heap)
GC.stat(stat)
ensure
GC.enable if reenable_gc
end
assert_equal (GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE] + GC::INTERNAL_CONSTANTS[:RVALUE_OVERHEAD]) * (2**i), stat_heap[:slot_size]
@ -768,23 +765,17 @@ class TestGc < Test::Unit::TestCase
end
def test_gc_disabled_start
begin
disabled = GC.disable
EnvUtil.without_gc do
c = GC.count
GC.start
assert_equal 1, GC.count - c
ensure
GC.enable unless disabled
end
begin
disabled = GC.disable
EnvUtil.without_gc do
c = GC.count
GC.start(immediate_mark: false, immediate_sweep: false)
10_000.times { Object.new }
assert_equal 1, GC.count - c
ensure
GC.enable unless disabled
end
end
@ -859,8 +850,7 @@ class TestGc < Test::Unit::TestCase
end
def test_old_to_young_reference
original_gc_disabled = GC.disable
EnvUtil.without_gc do
require "objspace"
old_obj = Object.new
@ -880,7 +870,6 @@ class TestGc < Test::Unit::TestCase
# Takes 4 GC to promote to old generation
GC.start
assert_include ObjectSpace.dump(young_obj), '"old":true'
ensure
GC.enable if !original_gc_disabled
end
end
end

View File

@ -191,7 +191,7 @@ End
end
def test_finalizer_thread_raise
GC.disable
EnvUtil.without_gc do
fzer = proc do |id|
sleep 0.2
end
@ -213,8 +213,7 @@ End
assert(false)
rescue my_error
end
ensure
GC.enable
end
end
def test_each_object

View File

@ -4,14 +4,13 @@ require 'etc'
class TestSleep < Test::Unit::TestCase
def test_sleep_5sec
GC.disable
EnvUtil.without_gc do
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
sleep 5
slept = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
bottom = 5.0
assert_operator(slept, :>=, bottom)
assert_operator(slept, :<=, 6.0, "[ruby-core:18015]: longer than expected")
ensure
GC.enable
end
end
end

View File

@ -6,8 +6,8 @@ class TestStringMemory < Test::Unit::TestCase
def capture_allocations(klass)
allocations = []
EnvUtil.without_gc do
GC.start
GC.disable
generation = GC.count
ObjectSpace.trace_object_allocations do
@ -30,8 +30,7 @@ class TestStringMemory < Test::Unit::TestCase
# (the parallel testing framework may create strings in a separate thread)
path == __FILE__
end
ensure
GC.enable
end
end
def test_byteslice_prefix