test/ruby: reap zombies

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41415 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-06-19 07:47:12 +00:00
parent c4561c2934
commit 4835230fef
5 changed files with 19 additions and 6 deletions

View File

@ -248,12 +248,13 @@ class TestFiber < Test::Unit::TestCase
def test_fork_from_fiber def test_fork_from_fiber
begin begin
Process.fork{} pid = Process.fork{}
rescue NotImplementedError rescue NotImplementedError
return return
else
Process.wait(pid)
end end
bug5700 = '[ruby-core:41456]' bug5700 = '[ruby-core:41456]'
pid = nil
assert_nothing_raised(bug5700) do assert_nothing_raised(bug5700) do
Fiber.new{ pid = fork {} }.resume Fiber.new{ pid = fork {} }.resume
end end

View File

@ -922,9 +922,14 @@ class TestIO < Test::Unit::TestCase
args = ['-e', '$>.write($<.read)'] if args.empty? args = ['-e', '$>.write($<.read)'] if args.empty?
ruby = EnvUtil.rubybin ruby = EnvUtil.rubybin
f = IO.popen([ruby] + args, 'r+') f = IO.popen([ruby] + args, 'r+')
pid = f.pid
yield(f) yield(f)
ensure ensure
f.close unless !f || f.closed? f.close unless !f || f.closed?
begin
Process.wait(pid)
rescue Errno::ECHILD, Errno::ESRCH
end
end end
def test_try_convert def test_try_convert

View File

@ -382,7 +382,7 @@ class TestRequire < Test::Unit::TestCase
File.open("a/tst.rb", "w") {|f| f.puts 'require_relative "lib"' } File.open("a/tst.rb", "w") {|f| f.puts 'require_relative "lib"' }
begin begin
File.symlink("../a/tst.rb", "b/tst.rb") File.symlink("../a/tst.rb", "b/tst.rb")
result = IO.popen([EnvUtil.rubybin, "b/tst.rb"]).read result = IO.popen([EnvUtil.rubybin, "b/tst.rb"], &:read)
assert_equal("a/lib.rb\n", result, "[ruby-dev:40040]") assert_equal("a/lib.rb\n", result, "[ruby-dev:40040]")
rescue NotImplementedError rescue NotImplementedError
skip "File.symlink is not implemented" skip "File.symlink is not implemented"

View File

@ -472,6 +472,7 @@ class TestRubyOptions < Test::Unit::TestCase
end end
assert_match(/hello world/, ps) assert_match(/hello world/, ps)
Process.kill :KILL, pid Process.kill :KILL, pid
Process.wait(pid)
end end
end end

View File

@ -6,7 +6,7 @@ require_relative 'envutil'
class TestSignal < Test::Unit::TestCase class TestSignal < Test::Unit::TestCase
def have_fork? def have_fork?
begin begin
Process.fork {} Process.wait(Process.fork {})
return true return true
rescue NotImplementedError rescue NotImplementedError
return false return false
@ -52,7 +52,6 @@ class TestSignal < Test::Unit::TestCase
end end
def test_exit_action def test_exit_action
return unless have_fork? # skip this test
begin begin
r, w = IO.pipe r, w = IO.pipe
r0, w0 = IO.pipe r0, w0 = IO.pipe
@ -68,12 +67,17 @@ class TestSignal < Test::Unit::TestCase
sleep 0.1 sleep 0.1
assert_nothing_raised("[ruby-dev:26128]") { assert_nothing_raised("[ruby-dev:26128]") {
Process.kill(:USR1, pid) Process.kill(:USR1, pid)
term = :TERM
begin begin
Timeout.timeout(3) { Timeout.timeout(3) {
Process.waitpid pid Process.waitpid pid
} }
rescue Timeout::Error rescue Timeout::Error
Process.kill(:TERM, pid) if term
Process.kill(term, pid)
term = (:KILL if term != :KILL)
retry
end
raise raise
end end
} }
@ -195,6 +199,8 @@ class TestSignal < Test::Unit::TestCase
end end
w.close w.close
assert_equal(r.read, "foo") assert_equal(r.read, "foo")
ensure
Process.wait(pid) if pid
end end
def test_signal_requiring def test_signal_requiring