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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2018-06-20 23:38:16 +00:00
parent 34dbd74f0c
commit 6c83a3ab60

View File

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