From 9bf5f12f33a49791ab00c1b51b32998a4e5dc228 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Mon, 30 Oct 2023 09:32:37 +0100 Subject: [PATCH] Add tests for `$LOAD_PATH.dup` and `Ractor.make_shareable` --- CHANGELOG.md | 2 ++ lib/bootsnap/load_path_cache/change_observer.rb | 10 ++-------- test/load_path_cache/change_observer_test.rb | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dac8c5c..ec47d4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +* Ensure `$LOAD_PATH.dup` is Ractor shareable to fix an conflit with `did_you_mean`. +* Allow to ignore direcotries using absolute paths. * Support YAML and JSON CompileCache on TruffleRuby. * Support LoadPathCache on TruffleRuby. diff --git a/lib/bootsnap/load_path_cache/change_observer.rb b/lib/bootsnap/load_path_cache/change_observer.rb index b209ab8..f2472c0 100644 --- a/lib/bootsnap/load_path_cache/change_observer.rb +++ b/lib/bootsnap/load_path_cache/change_observer.rb @@ -56,16 +56,10 @@ def uniq!(*args) end def dup - new_obj = super - new_obj.remove_instance_variable(:@lpc_observer) - new_obj + [] + self end - def clone - new_obj = super - ChangeObserver.unregister(new_obj) - new_obj - end + alias_method :clone, :dup end def self.register(arr, observer) diff --git a/test/load_path_cache/change_observer_test.rb b/test/load_path_cache/change_observer_test.rb index 4957fcc..108f0b5 100644 --- a/test/load_path_cache/change_observer_test.rb +++ b/test/load_path_cache/change_observer_test.rb @@ -10,6 +10,7 @@ class ChangeObserverTest < Minitest::Test def setup super @observer = Object.new + @observer.instance_variable_set(:@mutex, Mutex.new) @arr = [] ChangeObserver.register(@arr, @observer) end @@ -78,6 +79,20 @@ def test_register_twice_observes_once assert_equal(%w(a), @arr) end + def test_dup_returns_ractor_shareable_instance + return unless defined?(Ractor) + + ChangeObserver.register(@arr, @observer) + Ractor.make_shareable(@arr.dup.freeze) + end + + def test_clone_returns_ractor_shareable_instance + return unless defined?(Ractor) + + ChangeObserver.register(@arr, @observer) + Ractor.make_shareable(@arr.clone.freeze) + end + def test_uniq_without_block @observer.expects(:reinitialize).never @arr.uniq!