Skip to content

Commit

Permalink
Add tests for $LOAD_PATH.dup and Ractor.make_shareable
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Oct 30, 2023
1 parent 31cd669 commit 9bf5f12
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
10 changes: 2 additions & 8 deletions lib/bootsnap/load_path_cache/change_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions test/load_path_cache/change_observer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down

0 comments on commit 9bf5f12

Please sign in to comment.