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

ruby-changes:63024

From: Quang-Minh <ko1@a...>
Date: Sun, 20 Sep 2020 23:11:07 +0900 (JST)
Subject: [ruby-changes:63024] be2efb118f (master): Fulfill missing tests and stabilize tests

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

From be2efb118f73e73d35ba1473fd08a1550ff07fde Mon Sep 17 00:00:00 2001
From: Quang-Minh Nguyen <nguyenquangminh0711@g...>
Date: Sun, 20 Sep 2020 13:17:18 +0700
Subject: Fulfill missing tests and stabilize tests


diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index 9cfd42c..86325f0 100644
--- a/bootstraptest/test_ractor.rb
+++ b/bootstraptest/test_ractor.rb
@@ -22,20 +22,12 @@ assert_equal 'nil', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L22
   r.name.inspect
 }
 
-# Raises exceptions if initialize with invalid name
-assert_equal 'no implicit conversion of Array into String', %q{
+# Raises exceptions if initialize with an invalid name
+assert_equal 'ok', %q{
   begin
     r = Ractor.new(name: [{}]) {}
   rescue TypeError => e
-    e.message
-  end
-}
-
-assert_equal 'ASCII incompatible encoding (UTF-16BE)', %q{
-  begin
-    r = Ractor.new(name: String.new('Invalid encoding', encoding: 'UTF-16BE')) {}
-  rescue ArgumentError => e
-    e.message
+    'ok'
   end
 }
 
@@ -49,23 +41,24 @@ assert_equal "must be called with a block", %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L41
 }
 
 # Ractor#inspect
+# Return only id and status for main ractor
 assert_equal "#<Ractor:#1 running>", %q{
   Ractor.current.inspect
 }
 
-assert_match /^#<Ractor:#([^ ]*?) bootstraptest.tmp.rb:[0-9]+ blocking>$/, %q{
-  r = Ractor.new { Ractor.recv }
-  r.inspect
-}
-
-assert_match /^#<Ractor:#([^ ]*?) bootstraptest.tmp.rb:[0-9]+ terminated>$/, %q{
+# Return id, loc, and status for no-name ractor
+assert_match /^#<Ractor:#([^ ]*?) .+:[0-9]+ terminated>$/, %q{
   r = Ractor.new { '' }
   r.take
+  sleep 0.1 until r.inspect =~ /terminated/
   r.inspect
 }
 
-assert_match /^#<Ractor:#([^ ]*?) Test Ractor bootstraptest.tmp.rb:[0-9]+ blocking>$/, %q{
-  r = Ractor.new(name: 'Test Ractor') { Ractor.recv }
+# Return id, name, loc, and status for named ractor
+assert_match /^#<Ractor:#([^ ]*?) Test Ractor .+:[0-9]+ terminated>$/, %q{
+  r = Ractor.new(name: 'Test Ractor') { '' }
+  r.take
+  sleep 0.1 until r.inspect =~ /terminated/
   r.inspect
 }
 
@@ -154,7 +147,7 @@ assert_equal 'true', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L147
       rs.delete(r)
     }
 
-    if as.map{|r, o| r.inspect}.sort == all_rs.map{|r| r.inspect}.sort &&
+    if as.map{|r, o| r.object_id}.sort == all_rs.map{|r| r.object_id}.sort &&
        as.map{|r, o| o}.sort == (1..n).map{|i| "r#{i}"}.sort
       'ok'
     else
@@ -174,7 +167,7 @@ assert_equal 'ok', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L167
   end
 
   r.take
-  sleep 0.1 # wait for terminate
+  sleep 0.1 until r.inspect =~ /terminated/
 
   begin
     o = r.take
@@ -190,7 +183,52 @@ assert_equal 'ok', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L183
   end
 
   r.take # closed
-  sleep 0.1 # wait for terminate
+  sleep 0.1 until r.inspect =~ /terminated/
+
+  begin
+    r.send(1)
+  rescue Ractor::ClosedError
+    'ok'
+  else
+    'ng'
+  end
+}
+
+# Raise Ractor::ClosedError when try to send into a closed actor
+assert_equal 'ok', %q{
+  r = Ractor.new { Ractor.recv }
+
+  r.close
+  begin
+    r.send(1)
+  rescue Ractor::ClosedError
+    'ok'
+  else
+    'ng'
+  end
+}
+
+# Raise Ractor::ClosedError when try to take from closed actor
+assert_equal 'ok', %q{
+  r = Ractor.new do
+    Ractor.yield 1
+    Ractor.recv
+  end
+
+  r.close
+  begin
+    r.take
+  rescue Ractor::ClosedError
+    'ok'
+  else
+    'ng'
+  end
+}
+
+# Raise Ractor::ClosedError when try to send into a ractor with closed incoming port
+assert_equal 'ok', %q{
+  r = Ractor.new { Ractor.recv }
+  r.close_incoming
 
   begin
     r.send(1)
@@ -201,6 +239,50 @@ assert_equal 'ok', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L239
   end
 }
 
+# A ractor with closed incoming port still can send messages out
+assert_equal '[1, 2]', %q{
+  r = Ractor.new do
+    Ractor.yield 1
+    2
+  end
+  r.close_incoming
+
+  [r.take, r.take]
+}
+
+# Raise Ractor::ClosedError when try to take from a ractor with closed outgoing port
+assert_equal 'ok', %q{
+  r = Ractor.new do
+    Ractor.yield 1
+    Ractor.recv
+  end
+
+  r.close_outgoing
+  begin
+    r.take
+  rescue Ractor::ClosedError
+    'ok'
+  else
+    'ng'
+  end
+}
+
+# A ractor with closed outgoing port still can receive messages from incoming port
+assert_equal 'ok', %q{
+  r = Ractor.new do
+    Ractor.recv
+  end
+
+  r.close_outgoing
+  begin
+    r.send(1)
+  rescue Ractor::ClosedError
+    'ng'
+  else
+    'ok'
+  end
+}
+
 # multiple Ractors can recv (wait) from one Ractor
 assert_equal '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]', %q{
   pipe = Ractor.new do
@@ -559,6 +641,28 @@ assert_equal '[1000, 3]', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L641
   Ractor.new{ [A.size, H.size] }.take
 }
 
+# Ractor.count
+assert_equal '[1, 4, 3, 2, 1]', %q{
+  counts = []
+  counts << Ractor.count
+  ractors = (1..3).map { Ractor.new { Ractor.recv } }
+  counts << Ractor.count
+
+  ractors[0].send('End 0').take
+  sleep 0.1 until ractors[0].inspect =~ /terminated/
+  counts << Ractor.count
+
+  ractors[1].send('End 1').take
+  sleep 0.1 until ractors[1].inspect =~ /terminated/
+  counts << Ractor.count
+
+  ractors[2].send('End 2').take
+  sleep 0.1 until ractors[2].inspect =~ /terminated/
+  counts << Ractor.count
+
+  counts.inspect
+}
+
 ###
 ### Synchronization tests
 ###
-- 
cgit v0.10.2


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

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