1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

test/lib/envutil.rb (EnvUtil.timeout): added.

It is a wrapper for Timeout.timeout with the scale factor applied.
This commit is contained in:
Yusuke Endoh 2019-05-26 17:19:46 +09:00
parent 02b39daef8
commit 4668a3a9da
2 changed files with 9 additions and 3 deletions

View file

@ -65,6 +65,13 @@ module EnvUtil
end
module_function :apply_timeout_scale
def timeout(sec, klass = nil, message = nil, &blk)
return yield(sec) if sec == nil or sec.zero?
sec = apply_timeout_scale(sec)
Timeout.timeout(sec, klass, message, &blk)
end
module_function :timeout
def terminate(pid, signal = :TERM, pgroup = nil, reprieve = 1)
reprieve = apply_timeout_scale(reprieve) if reprieve

View file

@ -633,7 +633,7 @@ class TestRubyOptions < Test::Unit::TestCase
assert_match(/hello world/, ps)
assert_operator now, :<, stop
Process.kill :KILL, pid
Timeout.timeout(5) { Process.wait(pid) }
EnvUtil.timeout(5) { Process.wait(pid) }
end
end
@ -790,9 +790,8 @@ class TestRubyOptions < Test::Unit::TestCase
m.print("\C-d")
pid = spawn(EnvUtil.rubybin, :in => s, :out => w)
w.close
timeout = EnvUtil.apply_timeout_scale(3)
assert_nothing_raised('[ruby-dev:37798]') do
result = Timeout.timeout(timeout) {r.read}
result = EnvUtil.timeout(3) {r.read}
end
Process.wait pid
}