From f0603a781b5b0bb9fecc0e33752362df0722e07d Mon Sep 17 00:00:00 2001 From: Watson Date: Sun, 10 Dec 2023 13:07:41 +0900 Subject: [PATCH] Add GC.verify_compaction_references --- test/helper.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/helper.rb b/test/helper.rb index 06b15f5..65b66e5 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -62,5 +62,21 @@ def prepare_table session.execute(statement) end +def verify_gc_compaction + # This method was added in Ruby 3.0.0. Calling it this way asks the GC to + # move objects around, helping to find object movement bugs. + if defined?(GC.verify_compaction_references) == 'method' + if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.2.0') + GC.verify_compaction_references(expand_heap: true, toward: :empty) + else + GC.verify_compaction_references(double_heap: true, toward: :empty) + end + end +end + +at_exit do + verify_gc_compaction +end + prepare_keyspace prepare_table