[前][次][番号順一覧][スレッド一覧]

ruby-changes:63095

From: Koichi <ko1@a...>
Date: Fri, 25 Sep 2020 13:08:10 +0900 (JST)
Subject: [ruby-changes:63095] 6081ba4a87 (master): refactoring a test code.

https://git.ruby-lang.org/ruby.git/commit/?id=6081ba4a87

From 6081ba4a871f857eabdcb1e51b68f11bb10c49af Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Fri, 25 Sep 2020 13:07:07 +0900
Subject: refactoring a test code.

make a test more clear.

diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index 025d886..f06513a 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{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L417
 }
 
 # 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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]