[DRE-commits] [ruby-aruba] 28/74: Handle a command which stopped before you send the signal to it

Hideki Yamane henrich at moszumanska.debian.org
Sat Nov 28 01:16:34 UTC 2015


This is an automated email from the git hooks/post-receive script.

henrich pushed a commit to branch debian/sid
in repository ruby-aruba.

commit 1a8d017bafcf3b9d89717e1b0672ee87ba2bca01
Author: Dennis Günnewig <dg1 at ratiodata.de>
Date:   Tue Nov 24 12:00:52 2015 +0100

    Handle a command which stopped before you send the signal to it
---
 features/api/command/send_signal.feature | 18 ++++++++++++++++++
 lib/aruba/errors.rb                      |  3 +++
 lib/aruba/processes/spawn_process.rb     |  4 ++++
 3 files changed, 25 insertions(+)

diff --git a/features/api/command/send_signal.feature b/features/api/command/send_signal.feature
index 6e65207..a124b79 100644
--- a/features/api/command/send_signal.feature
+++ b/features/api/command/send_signal.feature
@@ -33,3 +33,21 @@ Feature: Send running command a signal
     """
     When I run `rspec`
     Then the specs should all pass
+
+  Scenario: Dying command
+    Given an executable named "bin/cli" with:
+    """ruby
+    #!/usr/bin/env bash
+    exit 1
+    """
+    And a file named "spec/run_spec.rb" with:
+    """ruby
+    require 'spec_helper'
+
+    RSpec.describe 'Run command', :type => :aruba, :exit_timeout => 3, :startup_wait_time => 2 do
+      before(:each) { run('cli') }
+      it { expect { last_command_started.send_signal 'HUP' }.to raise_error Aruba::CommandAlreadyStoppedError, /Command "cli" with PID/ }
+    end
+    """
+    When I run `rspec`
+    Then the specs should all pass
diff --git a/lib/aruba/errors.rb b/lib/aruba/errors.rb
index ba53ade..26698e7 100644
--- a/lib/aruba/errors.rb
+++ b/lib/aruba/errors.rb
@@ -10,4 +10,7 @@ module Aruba
 
   # Raised if one tries to use an unknown configuration option
   class UnknownOptionError < ArgumentError; end
+
+  # Rais if command already died
+  class CommandAlreadyStoppedError < Error; end
 end
diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb
index 7c62507..a8da8bd 100644
--- a/lib/aruba/processes/spawn_process.rb
+++ b/lib/aruba/processes/spawn_process.rb
@@ -233,7 +233,11 @@ module Aruba
       # @param [String] signal
       #   The signal, i.e. 'TERM'
       def send_signal(signal)
+        fail CommandAlreadyStoppedError, %(Command "#{commandline}" with PID "#{pid}" has already stopped.) if @process.exited?
+
         Process.kill signal, pid
+      rescue Errno::ESRCH
+        raise CommandAlreadyStoppedError, %(Command "#{commandline}" with PID "#{pid}" has already stopped.)
       end
 
       private

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-aruba.git



More information about the Pkg-ruby-extras-commits mailing list