[DRE-commits] [ruby-aruba] 07/74: Terminate/Stop command via cucumber steps
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 4af940822663b69a1b7336c8668d90be7514edfa
Author: Max Meyer <dev at fedux.org>
Date: Wed Nov 18 16:47:31 2015 +0100
Terminate/Stop command via cucumber steps
---
features/steps/commands/run.feature | 1 +
features/steps/commands/stop.feature | 237 +++++++++++++++++++++++++++++++++++
lib/aruba/cucumber/command.rb | 20 +++
3 files changed, 258 insertions(+)
diff --git a/features/steps/commands/run.feature b/features/steps/commands/run.feature
index ec99c0b..ec45ac9 100644
--- a/features/steps/commands/run.feature
+++ b/features/steps/commands/run.feature
@@ -19,3 +19,4 @@ Feature: Run commands
"""
When I run `cucumber`
Then the features should all pass
+
diff --git a/features/steps/commands/stop.feature b/features/steps/commands/stop.feature
new file mode 100644
index 0000000..7f04bcf
--- /dev/null
+++ b/features/steps/commands/stop.feature
@@ -0,0 +1,237 @@
+Feature: Stop commands
+
+ After you've started a command, you might want to stop a command. To do that
+ you've got multiple possibilities.
+
+ Background:
+ Given I use a fixture named "cli-app"
+
+ Scenario: Terminate last command started
+
+ Terminating a command will send `SIGTERM` to the command.
+
+ Given an executable named "bin/cli1" with:
+ """bash
+ #!/bin/bash
+
+ function term {
+ echo Command1
+ exit 1
+ }
+
+ trap term TERM
+ while [ true ]; do sleep 1; done
+ """
+ And an executable named "bin/cli2" with:
+ """bash
+ #!/bin/bash
+
+ function term {
+ echo Command2
+ exit 0
+ }
+
+ trap term TERM
+ while [ true ]; do sleep 1; done
+ exit 2
+ """
+ And a file named "features/stop.feature" with:
+ """
+ Feature: Run it
+ Background:
+ Given the default aruba exit timeout is 1 second
+
+ Scenario: Run command
+ Given I run `cli1`
+ And I run `cli2`
+ When I terminate the command started last
+ Then the exit status should be 0
+ And the output should contain:
+ \"\"\"
+ Command2
+ \"\"\"
+ """
+ When I run `cucumber`
+ Then the features should all pass
+
+ Scenario: Stop last command started
+
+ Stopping a command will wait n seconds for the command to stop and then
+ send `SIGTERM` to the command. Normally "n" is defined by the default exit
+ timeout of aruba.
+
+ Given an executable named "bin/cli1" with:
+ """bash
+ #!/bin/bash
+
+ function term {
+ echo Command1
+ exit 1
+ }
+
+ trap term TERM
+ while [ true ]; do sleep 1; done
+ """
+ And an executable named "bin/cli2" with:
+ """bash
+ #!/bin/bash
+
+ function term {
+ echo Command2
+ exit 0
+ }
+
+ trap term TERM
+ while [ true ]; do sleep 1; done
+ exit 2
+ """
+ And a file named "features/stop.feature" with:
+ """
+ Feature: Run it
+ Background:
+ Given the default aruba exit timeout is 1 second
+
+ Scenario: Run command
+ Given I run `cli1`
+ And I run `cli2`
+ When I stop the command started last
+ Then the exit status should be 0
+ And the output should contain:
+ \"\"\"
+ Command2
+ \"\"\"
+ """
+ When I run `cucumber`
+ Then the features should all pass
+
+ Scenario: Terminate command given by commandline
+
+ Terminating a command will send `SIGTERM` to the command.
+
+ Given an executable named "bin/cli1" with:
+ """bash
+ #!/bin/bash
+
+ function term {
+ echo Command1
+ exit 1
+ }
+
+ trap term TERM
+ while [ true ]; do sleep 1; done
+ """
+ And an executable named "bin/cli2" with:
+ """bash
+ #!/bin/bash
+
+ function term {
+ echo Command2
+ exit 0
+ }
+
+ trap term TERM
+ while [ true ]; do sleep 1; done
+ exit 2
+ """
+ And a file named "features/stop.feature" with:
+ """
+ Feature: Run it
+ Background:
+ Given the default aruba exit timeout is 1 second
+
+ Scenario: Run command
+ Given I run `cli1`
+ And I run `cli2`
+ When I terminate the command "cli1"
+ Then the exit status should be 0
+ And the output should contain:
+ \"\"\"
+ Command2
+ \"\"\"
+ """
+ When I run `cucumber`
+ Then the features should all pass
+
+ Scenario: Stop last command given by commandline
+
+ Stopping a command will wait n seconds for the command to stop and then
+ send `SIGTERM` to the command. Normally "n" is defined by the default exit
+ timeout of aruba.
+
+ Given an executable named "bin/cli1" with:
+ """bash
+ #!/bin/bash
+
+ function term {
+ echo Command1
+ exit 1
+ }
+
+ trap term TERM
+ while [ true ]; do sleep 1; done
+ """
+ And an executable named "bin/cli2" with:
+ """bash
+ #!/bin/bash
+
+ function term {
+ echo Command2
+ exit 0
+ }
+
+ trap term TERM
+ while [ true ]; do sleep 1; done
+ exit 2
+ """
+ And a file named "features/stop.feature" with:
+ """
+ Feature: Run it
+ Background:
+ Given the default aruba exit timeout is 1 second
+
+ Scenario: Run command
+ Given I run `cli1`
+ And I run `cli2`
+ When I stop the command "cli1"
+ Then the exit status should be 0
+ And the output should contain:
+ \"\"\"
+ Command2
+ \"\"\"
+ """
+ When I run `cucumber`
+ Then the features should all pass
+
+ Scenario: Stop command with configured signal
+
+ You can define a default signal which is used to stop all commands.
+
+ Given an executable named "bin/cli" with:
+ """bash
+ #!/bin/bash
+ function usr1 {
+ echo "Exit..."
+ exit 0
+ }
+
+ function term {
+ echo "No! No exit here. Try USR1. I stop the command with exit 1."
+ exit 1
+ }
+
+ trap usr1 USR1
+ trap term TERM
+ while [ true ]; do sleep 1; done
+ """
+ And a file named "features/run.feature" with:
+ """
+ Feature: Run it
+ Scenario: Run command
+ Given the default aruba stop signal is "USR1"
+ And the default aruba exit timeout is 1 second
+ When I run `cli`
+ Then the exit status should be 0
+ """
+ When I run `cucumber`
+ Then the features should all pass
+
diff --git a/lib/aruba/cucumber/command.rb b/lib/aruba/cucumber/command.rb
index 94877c5..281bdd3 100644
--- a/lib/aruba/cucumber/command.rb
+++ b/lib/aruba/cucumber/command.rb
@@ -49,6 +49,26 @@ When(/^I pipe in (?:a|the) file(?: named)? "([^"]*)"$/) do |file|
close_input
end
+When(/^I stop the command (?:"([^"]*)"|(?:started last))$/) do |command|
+ if command
+ cmd = all_commands.find { |c| c.commandline == command }
+ fail ArgumentError, %(No command "#{command}" found) if cmd.nil?
+ cmd.stop(announcer)
+ else
+ last_command_started.stop(announcer)
+ end
+end
+
+When(/^I terminate the command (?:"([^"]*)"|(?:started last))$/) do |command|
+ if command
+ cmd = all_commands.find { |c| c.commandline == command }
+ fail ArgumentError, %(No command "#{command}" found) if cmd.nil?
+ cmd.terminate
+ else
+ last_command_started.terminate
+ end
+end
+
When(/^I stop the command(?: started last)? if (output|stdout|stderr) contains:$/) do |channel, expected|
fail %(Invalid output channel "#{channel}" chosen. Please choose one of "output, stdout or stderr") unless %w(output stdout stderr).include? channel
--
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