summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorMirek Klimos <myreggg@gmail.com>2022-12-10 10:35:31 -0800
committerGitHub <noreply@github.com>2022-12-10 13:35:31 -0500
commitea613c63608232bf33fd454fc6cd1ce20d63d82e (patch)
tree24428c814d601d17d98bcf8cd2f036ac992186ac /test/ruby
parent12003acbb9c2c2624be8c41c22c15e6d1fa3a42e (diff)
Expose need_major_gc via GC.latest_gc_info (#6791)
Notes
Notes: Merged-By: peterzhu2118 <peter@peterzhu.ca>
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_gc.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb
index e22d6436d4..937f303604 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -229,6 +229,7 @@ class TestGc < Test::Unit::TestCase
assert_equal :force, h[:major_by] if use_rgengc?
assert_equal :method, h[:gc_by]
assert_equal true, h[:immediate_sweep]
+ assert_equal true, h.key?(:need_major_by)
GC.stress = true
assert_equal :force, GC.latest_gc_info[:major_by]
@@ -246,6 +247,25 @@ class TestGc < Test::Unit::TestCase
assert_raise_with_message(ArgumentError, /\u{30eb 30d3 30fc}/) {GC.latest_gc_info(:"\u{30eb 30d3 30fc}")}
end
+ def test_latest_gc_info_need_major_by
+ return unless use_rgengc?
+ omit 'stress' if GC.stress
+
+ 3.times { GC.start }
+ assert_nil GC.latest_gc_info(:need_major_by)
+
+ # allocate objects until need_major_by is set or major GC happens
+ major_count = GC.stat(:major_gc_count)
+ objects = []
+ while GC.stat(:major_gc_count) == major_count && GC.latest_gc_info(:need_major_by).nil?
+ objects.append(100.times.map { '*' })
+ end
+
+ assert_not_nil GC.latest_gc_info(:need_major_by)
+ GC.start(full_mark: false) # should be upgraded to major
+ assert_not_nil GC.latest_gc_info(:major_by)
+ end
+
def test_stress_compile_send
assert_in_out_err(%w[--disable-gems], <<-EOS, [], [], "")
GC.stress = true