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

ruby-changes:51498

From: normal <ko1@a...>
Date: Thu, 21 Jun 2018 08:38:22 +0900 (JST)
Subject: [ruby-changes:51498] normal:r63708 (trunk): test/ruby/test_io.rb: fix timing sensitive test

normal	2018-06-21 08:38:16 +0900 (Thu, 21 Jun 2018)

  New Revision: 63708

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63708

  Log:
    test/ruby/test_io.rb: fix timing sensitive test
    
    For systems with sleepy timer thread disabled, the signal
    handler does not fire soon enough and we need to ensure the
    signal is received before we check its value.  So use a
    self-pipe here.

  Modified files:
    trunk/test/ruby/test_io.rb
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb	(revision 63707)
+++ test/ruby/test_io.rb	(revision 63708)
@@ -85,11 +85,16 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L85
   end
 
   def trapping_usr2
-    @usr1_rcvd  = 0
-    trap(:USR2) { @usr1_rcvd += 1 }
-    yield
+    @usr2_rcvd  = 0
+    r, w = IO.pipe
+    trap(:USR2) do
+      w.write([@usr2_rcvd += 1].pack('L'))
+    end
+    yield r
   ensure
     trap(:USR2, "DEFAULT")
+    w&.close
+    r&.close
   end
 
   def test_pipe
@@ -864,7 +869,7 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L869
         rescue Errno::EBADF
           skip "nonblocking IO for pipe is not implemented"
         end
-        trapping_usr2 do
+        trapping_usr2 do |rd|
           nr = 30
           begin
             pid = fork do
@@ -878,7 +883,7 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L883
             nr.times do
               assert_equal megacontent.bytesize, IO.copy_stream("megasrc", s1)
             end
-            assert_equal(1, @usr1_rcvd)
+            assert_equal(1, rd.read(4).unpack1('L'))
           ensure
             s1.close
             _, status = Process.waitpid2(pid) if pid

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

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