aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2020-09-25 13:07:07 +0900
committerKoichi Sasada <ko1@atdot.net>2020-09-25 13:07:07 +0900
commit6081ba4a871f857eabdcb1e51b68f11bb10c49af (patch)
tree17123a2794613dfc8c806bb7dff544137d691586
parentd247dedade684d8ba04da4af891791e5ab5878ef (diff)
downloadruby-6081ba4a871f857eabdcb1e51b68f11bb10c49af.tar.gz
refactoring a test code.
make a test more clear.
-rw-r--r--bootstraptest/test_ractor.rb66
1 files changed, 49 insertions, 17 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index 025d886152..f06513a784 100644
--- a/bootstraptest/test_ractor.rb
+++ b/bootstraptest/test_ractor.rb
@@ -417,32 +417,64 @@ assert_equal 'no _dump_data is defined for class Thread', %q{
}
# send sharable and unsharable objects
-assert_equal "[[[1, true], [:sym, true], [:xyzzy, true], [\"frozen\", true], " \
- "[(3/1), true], [(3+4i), true], [/regexp/, true], [C, true]], " \
- "[[\"mutable str\", false], [[:array], false], [{:hash=>true}, false]]]", %q{
- r = Ractor.new do
- while v = Ractor.recv
+assert_equal "ok", %q{
+ echo_ractor = Ractor.new do
+ loop do
+ v = Ractor.recv
Ractor.yield v
end
end
- class C
- end
+ class C; end
+ module M; end
+
+ shareable_objects = [
+ true,
+ false,
+ nil,
+ 1,
+ 1.1, # Float
+ 1+2r, # Rational
+ 3+4i, # Complex
+ 2**128, # Bignum
+ :sym, # Symbol
+ 'xyzzy'.to_sym, # dynamic symbol
+ 'frozen'.freeze, # frozen String
+ /regexp/, # regexp literal
+ /reg{true}exp/.freeze, # frozen dregexp
+ [1, 2].freeze, # frozen Array which only refers to shareable
+ {a: 1}.freeze, # frozen Hash which only refers to shareable
+ [{a: 1}.freeze, 'str'.freeze].freeze, # nested frozen container
+ C, # class
+ M, # module
+ Ractor.current, # Ractor
+ ]
+
+ unshareable_objects = [
+ 'mutable str'.dup,
+ [:array],
+ {hash: true},
+ ]
- sharable_objects = [1, :sym, 'xyzzy'.to_sym, 'frozen'.freeze, 1+2r, 3+4i, /regexp/, C]
+ results = []
- sr = sharable_objects.map{|o|
- r << o
- o2 = r.take
- [o, o.object_id == o2.object_id]
+ shareable_objects.map{|o|
+ echo_ractor << o
+ o2 = echo_ractor.take
+ results << "#{o} is copied" unless o.object_id == o2.object_id
}
- ur = unsharable_objects = ['mutable str'.dup, [:array], {hash: true}].map{|o|
- r << o
- o2 = r.take
- [o, o.object_id == o2.object_id]
+ unshareable_objects.map{|o|
+ echo_ractor << o
+ o2 = echo_ractor.take
+ results << "#{o.inspect} is not copied" if o.object_id == o2.object_id
}
- [sr, ur].inspect
+
+ if results.empty?
+ :ok
+ else
+ results.inspect
+ end
}
# frozen Objects are shareable