mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
envutil.rb: timeout_error argument to invoke_ruby
* test/lib/envutil.rb (invoke_ruby): add `timeout_error` optional keyword argument, the exception class to be raised if the target process timed out. if it is nil, no exception will be raised at timeout but the terminated output, error, and status will be returned. defaulted to Timeout::Error. * test/lib/envutil.rb (assert_separately): check outputs and status (including diagnostic reports) of timed-out process. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
876d664069
commit
7be21a316f
1 changed files with 11 additions and 10 deletions
|
@ -34,7 +34,7 @@ module EnvUtil
|
||||||
DEFAULT_SIGNALS.delete("TERM") if /mswin|mingw/ =~ RUBY_PLATFORM
|
DEFAULT_SIGNALS.delete("TERM") if /mswin|mingw/ =~ RUBY_PLATFORM
|
||||||
|
|
||||||
def invoke_ruby(args, stdin_data = "", capture_stdout = false, capture_stderr = false,
|
def invoke_ruby(args, stdin_data = "", capture_stdout = false, capture_stderr = false,
|
||||||
encoding: nil, timeout: 10, reprieve: 1,
|
encoding: nil, timeout: 10, reprieve: 1, timeout_error: Timeout::Error,
|
||||||
stdout_filter: nil, stderr_filter: nil,
|
stdout_filter: nil, stderr_filter: nil,
|
||||||
signal: :TERM,
|
signal: :TERM,
|
||||||
rubybin: EnvUtil.rubybin,
|
rubybin: EnvUtil.rubybin,
|
||||||
|
@ -67,10 +67,7 @@ module EnvUtil
|
||||||
th_stderr = Thread.new { err_p.read } if capture_stderr && capture_stderr != :merge_to_stdout
|
th_stderr = Thread.new { err_p.read } if capture_stderr && capture_stderr != :merge_to_stdout
|
||||||
in_p.write stdin_data.to_str unless stdin_data.empty?
|
in_p.write stdin_data.to_str unless stdin_data.empty?
|
||||||
in_p.close
|
in_p.close
|
||||||
if (!th_stdout || th_stdout.join(timeout)) && (!th_stderr || th_stderr.join(timeout))
|
unless (!th_stdout || th_stdout.join(timeout)) && (!th_stderr || th_stderr.join(timeout))
|
||||||
stdout = th_stdout.value if capture_stdout
|
|
||||||
stderr = th_stderr.value if capture_stderr && capture_stderr != :merge_to_stdout
|
|
||||||
else
|
|
||||||
signals = Array(signal).select do |sig|
|
signals = Array(signal).select do |sig|
|
||||||
DEFAULT_SIGNALS[sig.to_s] or
|
DEFAULT_SIGNALS[sig.to_s] or
|
||||||
DEFAULT_SIGNALS[Signal.signame(sig)]
|
DEFAULT_SIGNALS[Signal.signame(sig)]
|
||||||
|
@ -99,13 +96,17 @@ module EnvUtil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if timeout_error
|
||||||
bt = caller_locations
|
bt = caller_locations
|
||||||
raise Timeout::Error, "execution of #{bt.shift.label} expired", bt.map(&:to_s)
|
raise timeout_error, "execution of #{bt.shift.label} expired", bt.map(&:to_s)
|
||||||
end
|
end
|
||||||
|
status = $?
|
||||||
|
end
|
||||||
|
stdout = th_stdout.value if capture_stdout
|
||||||
|
stderr = th_stderr.value if capture_stderr && capture_stderr != :merge_to_stdout
|
||||||
out_p.close if capture_stdout
|
out_p.close if capture_stdout
|
||||||
err_p.close if capture_stderr && capture_stderr != :merge_to_stdout
|
err_p.close if capture_stderr && capture_stderr != :merge_to_stdout
|
||||||
Process.wait pid
|
status ||= Process.wait2(pid)[1]
|
||||||
status = $?
|
|
||||||
stdout = stdout_filter.call(stdout) if stdout_filter
|
stdout = stdout_filter.call(stdout) if stdout_filter
|
||||||
stderr = stderr_filter.call(stderr) if stderr_filter
|
stderr = stderr_filter.call(stderr) if stderr_filter
|
||||||
return stdout, stderr, status
|
return stdout, stderr, status
|
||||||
|
@ -385,7 +386,7 @@ module Test
|
||||||
eom
|
eom
|
||||||
args = args.dup
|
args = args.dup
|
||||||
args.insert((Hash === args.first ? 1 : 0), "--disable=gems", *$:.map {|l| "-I#{l}"})
|
args.insert((Hash === args.first ? 1 : 0), "--disable=gems", *$:.map {|l| "-I#{l}"})
|
||||||
stdout, stderr, status = EnvUtil.invoke_ruby(args, src, true, true, **opt)
|
stdout, stderr, status = EnvUtil.invoke_ruby(args, src, true, true, timeout_error: nil, **opt)
|
||||||
abort = status.coredump? || (status.signaled? && ABORT_SIGNALS.include?(status.termsig))
|
abort = status.coredump? || (status.signaled? && ABORT_SIGNALS.include?(status.termsig))
|
||||||
assert(!abort, FailDesc[status, nil, stderr])
|
assert(!abort, FailDesc[status, nil, stderr])
|
||||||
self._assertions += stdout[/^assertions=(\d+)/, 1].to_i
|
self._assertions += stdout[/^assertions=(\d+)/, 1].to_i
|
||||||
|
|
Loading…
Reference in a new issue