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:
parent
02b39daef8
commit
4668a3a9da
2 changed files with 9 additions and 3 deletions
|
@ -65,6 +65,13 @@ module EnvUtil
|
||||||
end
|
end
|
||||||
module_function :apply_timeout_scale
|
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)
|
def terminate(pid, signal = :TERM, pgroup = nil, reprieve = 1)
|
||||||
reprieve = apply_timeout_scale(reprieve) if reprieve
|
reprieve = apply_timeout_scale(reprieve) if reprieve
|
||||||
|
|
||||||
|
|
|
@ -633,7 +633,7 @@ class TestRubyOptions < Test::Unit::TestCase
|
||||||
assert_match(/hello world/, ps)
|
assert_match(/hello world/, ps)
|
||||||
assert_operator now, :<, stop
|
assert_operator now, :<, stop
|
||||||
Process.kill :KILL, pid
|
Process.kill :KILL, pid
|
||||||
Timeout.timeout(5) { Process.wait(pid) }
|
EnvUtil.timeout(5) { Process.wait(pid) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -790,9 +790,8 @@ class TestRubyOptions < Test::Unit::TestCase
|
||||||
m.print("\C-d")
|
m.print("\C-d")
|
||||||
pid = spawn(EnvUtil.rubybin, :in => s, :out => w)
|
pid = spawn(EnvUtil.rubybin, :in => s, :out => w)
|
||||||
w.close
|
w.close
|
||||||
timeout = EnvUtil.apply_timeout_scale(3)
|
|
||||||
assert_nothing_raised('[ruby-dev:37798]') do
|
assert_nothing_raised('[ruby-dev:37798]') do
|
||||||
result = Timeout.timeout(timeout) {r.read}
|
result = EnvUtil.timeout(3) {r.read}
|
||||||
end
|
end
|
||||||
Process.wait pid
|
Process.wait pid
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue