summaryrefslogtreecommitdiff
path: root/test/ruby/test_gc_compact.rb
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2019-04-23 12:10:52 -0700
committerAaron Patterson <tenderlove@ruby-lang.org>2019-04-23 14:21:15 -0700
commit75061f46ae646e821e9228caa5e3b7f23fa609f0 (patch)
tree9ea4054d0594295bfcf347c4a820fe4b3508ec24 /test/ruby/test_gc_compact.rb
parentcf930985da1ae15b66577ec8286e54ad04ccda78 (diff)
downloadruby-75061f46ae646e821e9228caa5e3b7f23fa609f0.tar.gz
Fix complex hash keys to work with compaction
For example when an array containing objects is a hash key, the contents of the array may move which can cause the hash value for the array to change. This commit makes the default `hash` value based off the object id, so the hash value will remain stable. Fixes test/shell/test_command_processor.rb
Diffstat (limited to 'test/ruby/test_gc_compact.rb')
-rw-r--r--test/ruby/test_gc_compact.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/test/ruby/test_gc_compact.rb b/test/ruby/test_gc_compact.rb
index a1e037b70b..b705f601da 100644
--- a/test/ruby/test_gc_compact.rb
+++ b/test/ruby/test_gc_compact.rb
@@ -121,4 +121,11 @@ class TestGCCompact < Test::Unit::TestCase
skip "couldn't get objects to collide" if collisions == 0
assert_operator collisions, :>, 0
end
+
+ def test_complex_hash_keys
+ list_of_objects = big_list
+ hash = list_of_objects.hash
+ GC.verify_compaction_references
+ assert_equal hash, list_of_objects.hash
+ end
end