From b46441824fc1f666b9231f01f2f8ce9f7ac7b3ba Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 14 Dec 2013 22:34:43 +0000 Subject: [PATCH] test_process.rb: handshake * test/ruby/test_process.rb: handshake by pipe instead of sleep. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_process.rb | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 93b3254038..6586a06fa5 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -1186,10 +1186,14 @@ class TestProcess < Test::Unit::TestCase return unless Signal.list.include?("QUIT") with_tmpchdir do - write_file("foo", "sleep 30") - pid = spawn(RUBY, "foo") - Thread.new { sleep 1; Process.kill(:SIGQUIT, pid) } - Process.wait(pid) + write_file("foo", "puts;STDOUT.flush;sleep 30") + pid = nil + IO.pipe do |r, w| + pid = spawn(RUBY, "foo", out: w) + w.close + Thread.new { r.read(1); Process.kill(:SIGQUIT, pid) } + Process.wait(pid) + end t = Time.now s = $? assert_equal([false, true, false], @@ -1336,10 +1340,17 @@ class TestProcess < Test::Unit::TestCase end signal_received = [] Signal.trap(:CHLD) { signal_received << true } - pid = fork { sleep 0.1; exit } - Thread.start { raise } + pid = nil + IO.pipe do |r, w| + pid = fork { r.read(1); exit } + Thread.start { raise } + w.puts + end Process.wait pid - sleep 0.1 + 10.times do + break unless signal_received.empty? + sleep 0.01 + end assert_equal [true], signal_received, " [ruby-core:19744]" rescue NotImplementedError, ArgumentError ensure