[DRE-commits] [ruby-aruba] 08/74: Send a signal to command
Hideki Yamane
henrich at moszumanska.debian.org
Sat Nov 28 01:16:27 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 67b91097b99d14f50ffb537a744377ae240dd180
Author: Max Meyer <dev at fedux.org>
Date: Wed Nov 18 22:01:05 2015 +0100
Send a signal to command
---
features/api/command/send_signal.feature | 34 ++++++++++++++++++++++++++++++++
features/steps/commands/stop.feature | 26 ++++++++++++------------
lib/aruba/cucumber/command.rb | 22 ++++++++++++++++++---
lib/aruba/processes/basic_process.rb | 8 ++++++++
lib/aruba/processes/spawn_process.rb | 29 +++++++++++++++++++++------
5 files changed, 97 insertions(+), 22 deletions(-)
diff --git a/features/api/command/send_signal.feature b/features/api/command/send_signal.feature
new file mode 100644
index 0000000..fbd9fec
--- /dev/null
+++ b/features/api/command/send_signal.feature
@@ -0,0 +1,34 @@
+Feature: Send running command a signal
+
+ You can send a running command a signal using
+ `last_command_started#send_signal`. This is only supported with
+ `aruba.config.command_launcher = :spawn` (default).
+
+ Background:
+ Given I use a fixture named "cli-app"
+
+ Scenario: Existing executable
+ Given an executable named "bin/cli" with:
+ """ruby
+ #!/usr/bin/env ruby
+
+ Signal.trap 'USR1' do
+ $stderr.puts 'Exit...'
+ end
+
+ loop { sleep 1 }
+ """
+ And a file named "spec/run_spec.rb" with:
+ """ruby
+ require 'spec_helper'
+
+ RSpec.describe 'Run command', :type => :aruba, :exit_timeout => 3 do
+ before(:each) { run('cli') }
+ before(:each) { last_command_started.send_signal 'USR1' }
+ before(:each) { last_command_started.send_signal 'USR1' }
+ before(:each) { last_command_started.send_signal 'USR1' }
+ it { expect(last_command_started).to have_output /Exit/ }
+ end
+ """
+ When I run `rspec`
+ Then the specs should all pass
diff --git a/features/steps/commands/stop.feature b/features/steps/commands/stop.feature
index 7f04bcf..cdc552f 100644
--- a/features/steps/commands/stop.feature
+++ b/features/steps/commands/stop.feature
@@ -39,11 +39,11 @@ Feature: Stop commands
"""
Feature: Run it
Background:
- Given the default aruba exit timeout is 1 second
+ Given the default aruba exit timeout is 5 second
Scenario: Run command
- Given I run `cli1`
- And I run `cli2`
+ Given I run `cli1` in background
+ And I run `cli2` in background
When I terminate the command started last
Then the exit status should be 0
And the output should contain:
@@ -89,11 +89,11 @@ Feature: Stop commands
"""
Feature: Run it
Background:
- Given the default aruba exit timeout is 1 second
+ Given the default aruba exit timeout is 5 seconds
Scenario: Run command
- Given I run `cli1`
- And I run `cli2`
+ Given I run `cli1` in background
+ And I run `cli2` in background
When I stop the command started last
Then the exit status should be 0
And the output should contain:
@@ -137,11 +137,11 @@ Feature: Stop commands
"""
Feature: Run it
Background:
- Given the default aruba exit timeout is 1 second
+ Given the default aruba exit timeout is 5 seconds
Scenario: Run command
- Given I run `cli1`
- And I run `cli2`
+ Given I run `cli1` in background
+ And I run `cli2` in background
When I terminate the command "cli1"
Then the exit status should be 0
And the output should contain:
@@ -187,11 +187,11 @@ Feature: Stop commands
"""
Feature: Run it
Background:
- Given the default aruba exit timeout is 1 second
+ Given the default aruba exit timeout is 5 seconds
Scenario: Run command
- Given I run `cli1`
- And I run `cli2`
+ Given I run `cli1` in background
+ And I run `cli2` in background
When I stop the command "cli1"
Then the exit status should be 0
And the output should contain:
@@ -228,7 +228,7 @@ Feature: Stop commands
Feature: Run it
Scenario: Run command
Given the default aruba stop signal is "USR1"
- And the default aruba exit timeout is 1 second
+ And the default aruba exit timeout is 5 seconds
When I run `cli`
Then the exit status should be 0
"""
diff --git a/lib/aruba/cucumber/command.rb b/lib/aruba/cucumber/command.rb
index 281bdd3..6b46d53 100644
--- a/lib/aruba/cucumber/command.rb
+++ b/lib/aruba/cucumber/command.rb
@@ -35,6 +35,11 @@ When(/^I run `([^`]*)` interactively$/)do |cmd|
@interactive = run(cmd)
end
+# Merge interactive and background after refactoring with event queue
+When(/^I run `([^`]*)` in background$/)do |cmd|
+ run(sanitize_text(cmd))
+end
+
When(/^I type "([^"]*)"$/) do |input|
type(unescape_text(input))
end
@@ -59,13 +64,24 @@ When(/^I stop the command (?:"([^"]*)"|(?:started last))$/) do |command|
end
end
-When(/^I terminate the command (?:"([^"]*)"|(?:started last))$/) do |command|
+When(/^I (terminate|stop) the command (?:"([^"]*)"|(?:started last))$/) do |signal, command|
+ sleep 10
+
if command
cmd = all_commands.find { |c| c.commandline == command }
fail ArgumentError, %(No command "#{command}" found) if cmd.nil?
- cmd.terminate
+
+ if signal == 'terminate'
+ cmd.terminate
+ else
+ cmd.stop(announcer)
+ end
else
- last_command_started.terminate
+ if signal == 'terminate'
+ last_command_started.terminate
+ else
+ last_command_started.stop(announcer)
+ end
end
end
diff --git a/lib/aruba/processes/basic_process.rb b/lib/aruba/processes/basic_process.rb
index 23e69f1..478a067 100644
--- a/lib/aruba/processes/basic_process.rb
+++ b/lib/aruba/processes/basic_process.rb
@@ -53,6 +53,14 @@ module Aruba
NotImplementedError
end
+ def send_signal(*)
+ NotImplementedError
+ end
+
+ def wait
+ NotImplementedError
+ end
+
# Was process already stopped
def stopped?
@stopped == true
diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb
index a103731..a529bea 100644
--- a/lib/aruba/processes/spawn_process.rb
+++ b/lib/aruba/processes/spawn_process.rb
@@ -53,8 +53,8 @@ module Aruba
cmd = Aruba.platform.command_string.new(cmd)
@process = ChildProcess.build(*[cmd.to_a, arguments].flatten)
- @stdout_file = Tempfile.new("aruba-stdout-")
- @stderr_file = Tempfile.new("aruba-stderr-")
+ @stdout_file = Tempfile.new('aruba-stdout-')
+ @stderr_file = Tempfile.new('aruba-stderr-')
@stdout_file.sync = true
@stderr_file.sync = true
@@ -175,9 +175,10 @@ module Aruba
@timed_out = true
if @stop_signal
- Process.kill @stop_signal, pid
- # set the exit status
- @process.wait
+ # send stop signal ...
+ send_signal @stop_signal
+ # ... and set the exit status
+ wait
else
@process.stop
end
@@ -198,11 +199,19 @@ module Aruba
end
# rubocop:enable Metrics/MethodLength
+ # Wait for command to finish
+ def wait
+ return if @process.nil?
+
+ @process.wait
+ end
+
+ # Terminate command
def terminate
return unless @process
if @stop_signal
- Process.kill @stop_signal, pid
+ send_signal @stop_signal
else
@process.stop
end
@@ -217,6 +226,14 @@ module Aruba
@process.pid
end
+ # Send command a signal
+ #
+ # @param [String] signal
+ # The signal, i.e. 'TERM'
+ def send_signal(signal)
+ Process.kill signal, pid
+ end
+
private
def wait_for_io(time_to_wait, &block)
--
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