aboutsummaryrefslogtreecommitdiffstats
path: root/test/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-02 06:44:22 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-02 06:44:22 +0000
commit876d6640698e3b3be219d4a89b9aeedb9f17f62f (patch)
tree5d6ac0f65d92e0aaf41f2adf20c265e7faaf30e0 /test/lib
parent575d4a306945cfa8265667651fbf4357d3ff73ff (diff)
downloadruby-876d6640698e3b3be219d4a89b9aeedb9f17f62f.tar.gz
envutil.rb: signal list to invoke_ruby
* test/lib/envutil.rb (invoke_ruby): allow `signal` optional keyword argument to be a list of signals to be sent to the target process. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49805 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/envutil.rb36
1 files changed, 24 insertions, 12 deletions
diff --git a/test/lib/envutil.rb b/test/lib/envutil.rb
index 9fe804c66d..c63bc79b4e 100644
--- a/test/lib/envutil.rb
+++ b/test/lib/envutil.rb
@@ -30,10 +30,13 @@ module EnvUtil
LANG_ENVS = %w"LANG LC_ALL LC_CTYPE"
+ DEFAULT_SIGNALS = Signal.list
+ DEFAULT_SIGNALS.delete("TERM") if /mswin|mingw/ =~ RUBY_PLATFORM
+
def invoke_ruby(args, stdin_data = "", capture_stdout = false, capture_stderr = false,
encoding: nil, timeout: 10, reprieve: 1,
stdout_filter: nil, stderr_filter: nil,
- signal: (/mswin|mingw/ =~ RUBY_PLATFORM ? :KILL : :TERM),
+ signal: :TERM,
rubybin: EnvUtil.rubybin,
**opt)
in_c, in_p = IO.pipe
@@ -68,25 +71,34 @@ module EnvUtil
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|
+ DEFAULT_SIGNALS[sig.to_s] or
+ DEFAULT_SIGNALS[Signal.signame(sig)]
+ end
+ signals |= [:KILL]
case pgroup = opt[:pgroup]
when 0, true
pgroup = -pid
when nil, false
pgroup = pid
end
- begin
- Process.kill signal, pgroup
- Timeout.timeout((reprieve unless signal == :KILL)) do
+ while signal = signals.shift
+ begin
+ Process.kill signal, pgroup
+ rescue Errno::Invalid
+ next
+ rescue Errno::ESRCH
+ break
+ end
+ if signals.empty? or !reprieve
Process.wait(pid)
+ else
+ begin
+ Timeout.timeout(reprieve) {Process.wait(pid)}
+ rescue Timeout::Error
+ end
end
- rescue Errno::ESRCH
- break
- rescue Timeout::Error
- raise if signal == :KILL
- signal = :KILL
- else
- break
- end while true
+ end
bt = caller_locations
raise Timeout::Error, "execution of #{bt.shift.label} expired", bt.map(&:to_s)
end