summaryrefslogtreecommitdiff
path: root/bootstraptest
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2020-12-11 16:37:20 +0900
committerKoichi Sasada <ko1@atdot.net>2020-12-12 06:19:18 +0900
commitd741c77b5fd976300815c1ea987e76e92b71122f (patch)
tree852e8cc6d6d66193cbb54c0ac9d2b6e7a1a239d6 /bootstraptest
parent31e8de2920935d500105949bda931f3ca22cdbff (diff)
fix ivar with shareable objects issue
Instance variables of sharable objects are accessible only from main ractor, so we need to check it correctly.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3887
Diffstat (limited to 'bootstraptest')
-rw-r--r--bootstraptest/test_ractor.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index 2bbf823f37..81bea95e01 100644
--- a/bootstraptest/test_ractor.rb
+++ b/bootstraptest/test_ractor.rb
@@ -809,6 +809,53 @@ assert_equal 'can not access instance variables of shareable objects from non-ma
end
}
+# ivar in shareable-objects are not allowed to access from non-main Ractor, by @iv (get)
+assert_equal 'can not access instance variables of shareable objects from non-main Ractors', %q{
+ class Ractor
+ def setup
+ @foo = ''
+ end
+
+ def foo
+ @foo
+ end
+ end
+
+ shared = Ractor.new{}
+ shared.setup
+
+ r = Ractor.new shared do |shared|
+ p shared.foo
+ end
+
+ begin
+ r.take
+ rescue Ractor::RemoteError => e
+ e.cause.message
+ end
+}
+
+# ivar in shareable-objects are not allowed to access from non-main Ractor, by @iv (set)
+assert_equal 'can not access instance variables of shareable objects from non-main Ractors', %q{
+ class Ractor
+ def setup
+ @foo = ''
+ end
+ end
+
+ shared = Ractor.new{}
+
+ r = Ractor.new shared do |shared|
+ p shared.setup
+ end
+
+ begin
+ r.take
+ rescue Ractor::RemoteError => e
+ e.cause.message
+ end
+}
+
# But a shareable object is frozen, it is allowed to access ivars from non-main Ractor
assert_equal '11', %q{
[Object.new, [], ].map{|obj|