Permalink
Browse files

Add a kill method

  • Loading branch information...
1 parent 135407c commit 01518871382f61a0bd870b714036816ea87dc978 @gdb committed Oct 14, 2013
Showing with 36 additions and 2 deletions.
  1. +10 −1 lib/rubysh/runner.rb
  2. +1 −1 test/functional/lib/env.rb
  3. +25 −0 test/functional/lib/kill.rb
View
@@ -203,13 +203,22 @@ def target_state(target_name, reading=nil)
target_state
end
- private
+ def kill(signal='TERM')
+ my_pid = pid
+ unless my_pid
+ raise Rubysh::Error::BaseError.new("You haven't started this runner yet.")
+ end
+ Rubysh.log.debug("Sending #{signal} to #{my_pid}")
+ Process.kill(signal, my_pid)
+ end
def wait
run_io
do_wait
end
+ private
+
def targets_by_fd_numbers
@targets.inject({}) do |hash, (_, target_state)|
fd_num = target_state[:subprocess_fd_number]
@@ -1,7 +1,7 @@
require File.expand_path('../_lib', File.dirname(__FILE__))
module RubyshTest::Functional
- class TripleLessThanTest < FunctionalTest
+ class EnvTest < FunctionalTest
describe 'when using <<< string' do
it 'the string is delivered on stdin' do
ENV['TEST1'] = '1'
@@ -0,0 +1,25 @@
+require File.expand_path('../_lib', File.dirname(__FILE__))
+
+module RubyshTest::Functional
+ class KillTest < FunctionalTest
+ describe 'when killing' do
+ it 'delivers a sigterm by default' do
+ result = Rubysh.run_async('ruby', '-e', 'sleep 10', Rubysh.>)
+ result.kill
+ result.wait
+
+ assert_equal(nil, result.exitstatus)
+ assert_equal(Signal.list['TERM'], result.full_status.termsig)
+ end
+
+ it 'delivers the specified signal otherwise' do
+ result = Rubysh.run_async('ruby', '-e', 'sleep 10', Rubysh.>)
+ result.kill('KILL')
+ result.wait
+
+ assert_equal(nil, result.exitstatus)
+ assert_equal(Signal.list['KILL'], result.full_status.termsig)
+ end
+ end
+ end
+end

0 comments on commit 0151887

Please sign in to comment.