зеркало из https://github.com/github/ruby.git
[ruby/ostruct] Add test that frozen OpenStructs are Ractor-shareable
This commit is contained in:
Родитель
083fa6e5d2
Коммит
0977040133
|
@ -62,6 +62,8 @@
|
||||||
# first_pet # => #<OpenStruct name="Rowdy">
|
# first_pet # => #<OpenStruct name="Rowdy">
|
||||||
# first_pet == second_pet # => true
|
# first_pet == second_pet # => true
|
||||||
#
|
#
|
||||||
|
# Ractor compatibility: A frozen OpenStruct with shareable values is itself shareable.
|
||||||
|
#
|
||||||
# == Caveats
|
# == Caveats
|
||||||
#
|
#
|
||||||
# An OpenStruct utilizes Ruby's method lookup structure to find and define the
|
# An OpenStruct utilizes Ruby's method lookup structure to find and define the
|
||||||
|
|
|
@ -298,4 +298,15 @@ class TC_OpenStruct < Test::Unit::TestCase
|
||||||
o.foo = 42
|
o.foo = 42
|
||||||
assert_equal 42, o.foo
|
assert_equal 42, o.foo
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_ractor
|
||||||
|
obj1 = OpenStruct.new(a: 42, b: 42)
|
||||||
|
obj1.c = 42
|
||||||
|
obj1.freeze
|
||||||
|
|
||||||
|
obj2 = Ractor.new obj1 do |obj|
|
||||||
|
obj
|
||||||
|
end.take
|
||||||
|
assert obj1.object_id == obj2.object_id
|
||||||
|
end if defined?(Ractor)
|
||||||
end
|
end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче