ruby-changes:45095
From: nobu <ko1@a...>
Date: Sat, 24 Dec 2016 09:51:07 +0900 (JST)
Subject: [ruby-changes:45095] nobu:r57168 (trunk): test/unit.rb: --subprocess-timeout-scale option
nobu 2016-12-24 09:51:01 +0900 (Sat, 24 Dec 2016) New Revision: 57168 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57168 Log: test/unit.rb: --subprocess-timeout-scale option * test/lib/envutil.rb (EnvUtil#invoke_ruby): add subprocess timeout scaling factor. * test/lib/test/unit.rb (Test::Unit::SubprocessOption): add --subprocess-timeout-scale option. Modified files: trunk/test/lib/envutil.rb trunk/test/lib/test/unit.rb Index: test/lib/test/unit.rb =================================================================== --- test/lib/test/unit.rb (revision 57167) +++ test/lib/test/unit.rb (revision 57168) @@ -932,6 +932,21 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L932 end end + module SubprocessOption + def setup_options(parser, options) + super + parser.separator "subprocess options:" + parser.on '--subprocess-timeout-scale NUM', "Scale subprocess timeout", Float do |scale| + raise OptionParser::InvalidArgument, "timeout scale must be positive" unless scale > 0 + options[:timeout_scale] = scale + end + if scale = options[:timeout_scale] or + (scale = ENV["RUBY_TEST_SUBPROCESS_TIMEOUT_SCALE"] and (scale = scale.to_f) > 0) + EnvUtil.subprocess_timeout_scale = scale + end + end + end + class Runner < MiniTest::Unit # :nodoc: all include Test::Unit::Options include Test::Unit::StatusLine @@ -942,6 +957,7 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L957 include Test::Unit::LoadPathOption include Test::Unit::GCStressOption include Test::Unit::ExcludesOption + include Test::Unit::SubprocessOption include Test::Unit::RunCount class << self; undef autorun; end Index: test/lib/envutil.rb =================================================================== --- test/lib/envutil.rb (revision 57167) +++ test/lib/envutil.rb (revision 57168) @@ -40,12 +40,20 @@ module EnvUtil https://github.com/ruby/ruby/blob/trunk/test/lib/envutil.rb#L40 DEFAULT_SIGNALS = Signal.list DEFAULT_SIGNALS.delete("TERM") if /mswin|mingw/ =~ RUBY_PLATFORM + class << self + attr_accessor :subprocess_timeout_scale + end + def invoke_ruby(args, stdin_data = "", capture_stdout = false, capture_stderr = false, encoding: nil, timeout: 10, reprieve: 1, timeout_error: Timeout::Error, stdout_filter: nil, stderr_filter: nil, signal: :TERM, rubybin: EnvUtil.rubybin, **opt) + if scale = EnvUtil.subprocess_timeout_scale + timeout *= scale if timeout + reprieve *= scale if reprieve + end in_c, in_p = IO.pipe out_p, out_c = IO.pipe if capture_stdout err_p, err_c = IO.pipe if capture_stderr && capture_stderr != :merge_to_stdout -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/