summaryrefslogtreecommitdiff
path: root/test/ruby/test_weakkeymap.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_weakkeymap.rb')
-rw-r--r--test/ruby/test_weakkeymap.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/test/ruby/test_weakkeymap.rb b/test/ruby/test_weakkeymap.rb
index 5df53749ca..6b3ffbb81f 100644
--- a/test/ruby/test_weakkeymap.rb
+++ b/test/ruby/test_weakkeymap.rb
@@ -87,7 +87,7 @@ class TestWeakKeyMap < Test::Unit::TestCase
assert_nothing_raised(FrozenError) {@wm['foo'] = o}
end
- def test_inconsistent_hash_key
+ def test_inconsistent_hash_key_memory_leak
assert_no_memory_leak [], '', <<~RUBY
class BadHash
def initialize
@@ -108,6 +108,26 @@ class TestWeakKeyMap < Test::Unit::TestCase
RUBY
end
+ def test_compaction
+ omit "compaction is not supported on this platform" unless GC.respond_to?(:compact)
+
+ assert_separately(%w(-robjspace), <<-'end;')
+ wm = ObjectSpace::WeakKeyMap.new
+ key = Object.new
+ val = Object.new
+ wm[key] = val
+
+ GC.verify_compaction_references(expand_heap: true, toward: :empty)
+
+ assert_equal(val, wm[key])
+ end;
+ end
+
+ def test_gc_compact_stress
+ omit "compaction doesn't work well on s390x" if RUBY_PLATFORM =~ /s390x/ # https://github.com/ruby/ruby/pull/5077
+ EnvUtil.under_gc_compact_stress { ObjectSpace::WeakKeyMap.new }
+ end
+
private
def assert_weak_include(m, k, n = 100)