diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2019-05-26 17:19:46 +0900 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2019-05-26 17:23:14 +0900 |
commit | 4668a3a9da9f02b073631013e71722868ceafa53 (patch) | |
tree | da4b3288693f7bc88238063af1e01029451d99d1 /test | |
parent | 02b39daef834890981689f1f697c7c25cad55dd6 (diff) | |
download | ruby-4668a3a9da9f02b073631013e71722868ceafa53.tar.gz |
test/lib/envutil.rb (EnvUtil.timeout): added.
It is a wrapper for Timeout.timeout with the scale factor applied.
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/envutil.rb | 7 | ||||
-rw-r--r-- | test/ruby/test_rubyoptions.rb | 5 |
2 files changed, 9 insertions, 3 deletions
diff --git a/test/lib/envutil.rb b/test/lib/envutil.rb index f4d63d5a0a..f9c0e57fcf 100644 --- a/test/lib/envutil.rb +++ b/test/lib/envutil.rb @@ -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 diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 7dcae0c0e9..96edaca6f3 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -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 } |