summaryrefslogtreecommitdiff
path: root/bootstraptest/test_ractor.rb
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2020-10-30 16:48:42 +0900
committerKoichi Sasada <ko1@atdot.net>2020-10-30 16:52:09 +0900
commit89c8ca32d0a8542c9360f45734c799d81c4738ad (patch)
tree869918dad233fd763e2b2f6784e0ca23c418cc71 /bootstraptest/test_ractor.rb
parent08ddc335ea34829df756c164ceb13c56f0377d37 (diff)
add a test of define_method with shareable Proc.
a method defined by define_method with normal Proc can not cross ractors because the normal Proc is not shareable. However, shareable Proc can be crossed between ractors, so the method with shareable Proc should be called correctly.
Diffstat (limited to 'bootstraptest/test_ractor.rb')
-rw-r--r--bootstraptest/test_ractor.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index a61e741b54..65ea334bbb 100644
--- a/bootstraptest/test_ractor.rb
+++ b/bootstraptest/test_ractor.rb
@@ -933,6 +933,17 @@ assert_equal 'true', %q{
Ractor.shareable?(pr)
}
+# define_method() can invoke different Ractor's proc if the proc is shareable.
+assert_equal '1', %q{
+ class C
+ a = 1
+ define_method "foo", Ractor.make_shareable(Proc.new{ a })
+ a = 2
+ end
+
+ Ractor.new{ C.new.foo }.take
+}
+
# Ractor.make_shareable(a_proc) makes a proc shareable.
assert_equal 'can not make a Proc shareable because it accesses outer variables (a).', %q{
a = b = nil