[DRE-commits] [ruby-aruba] 34/74: Fixed tests for run

Hideki Yamane henrich at moszumanska.debian.org
Sat Nov 28 01:16:36 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 050772f8eeb2ece27f676f1b1cd1697b26c63db7
Author: Dennis Günnewig <dg1 at ratiodata.de>
Date:   Wed Nov 25 10:31:48 2015 +0100

    Fixed tests for run
---
 features/api/command/run.feature    | 102 ++++++++++++++++++++++-
 features/steps/command/stop.feature | 156 ++++++++++++++++++++++++++----------
 2 files changed, 215 insertions(+), 43 deletions(-)

diff --git a/features/api/command/run.feature b/features/api/command/run.feature
index d03bc92..2433937 100644
--- a/features/api/command/run.feature
+++ b/features/api/command/run.feature
@@ -1,6 +1,24 @@
 Feature: Run command
 
-  To run a command use the `#run`-method.
+  To run a command use the `#run`-method. There are some configuration options
+  which are relevant here:
+
+  - `startup_wait_time`:
+
+    Given this option `aruba` waits n seconds after it started the command.
+    This is most useful when using `#run()` and not really makes sense for
+    `#run_simple()`.
+
+    You can use `#run()` + `startup_wait_time` to start background jobs.
+
+  - `exit_timeout`:
+
+    The exit timeout is used, when `aruba` waits for a command to finished.
+
+  - `io_wait_timeout`:
+
+    The io wait timeout is used, when you access `stdout` or `stderr` of a
+    command.
 
   Background:
     Given I use a fixture named "cli-app"
@@ -53,3 +71,85 @@ Feature: Run command
     """
     When I run `rspec`
     Then the specs should all pass
+
+  Scenario: Command with long startup phase
+
+    If you have got a command with a long startup phase or use `ruby` together
+    with `bundler`, you should consider using the `startup_wait_time`-option.
+    Otherwise methods like `#send_signal` don't work since they require the
+    command to be running and have setup it's signal handler.
+
+    Given an executable named "bin/cli" with:
+    """bash
+    #!/usr/bin/env bash
+ 
+    function initialize_script {
+      sleep 2
+    }
+
+    function do_some_work {
+      echo "Hello, Aruba is working"
+    }
+
+    function recurring_work {
+      echo "Hello, Aruba here"
+    }
+
+    function stop_script {
+      exit 0
+    }
+
+    trap recurring_work HUP
+    trap stop_script TERM
+
+    initialize_script
+    do_some_work
+
+    while [ true ]; do sleep 1; done
+    """
+    And a file named "spec/run_spec.rb" with:
+    """ruby
+    require 'spec_helper'
+
+    RSpec.describe 'Run command', :type => :aruba, :exit_timeout => 1, :startup_wait_time => 2 do
+      before(:each) { run('cli') }
+      before(:each) { last_command_started.send_signal 'HUP' }
+
+      it { expect(last_command_started).to be_successfully_executed }
+      it { expect(last_command_started).to have_output /Hello, Aruba is working/ }
+      it { expect(last_command_started).to have_output /Hello, Aruba here/ }
+
+    end
+    """
+    When I run `rspec`
+    Then the specs should all pass
+
+  Scenario: Long running command
+
+    If you have got a "long running" command, you should consider using the
+    `exit_timeout`-option.
+
+    Given an executable named "bin/cli" with:
+    """bash
+    #!/usr/bin/env bash
+
+    function do_some_work {
+      sleep 2
+      echo "Hello, Aruba here"
+    }
+
+    do_some_work
+    """
+    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') }
+
+      it { expect(last_command_started).to be_successfully_executed }
+      it { expect(last_command_started).to have_output /Hello, Aruba here/ }
+    end
+    """
+    When I run `rspec`
+    Then the specs should all pass
diff --git a/features/steps/command/stop.feature b/features/steps/command/stop.feature
index 234eabe..41b39bb 100644
--- a/features/steps/command/stop.feature
+++ b/features/steps/command/stop.feature
@@ -3,6 +3,11 @@ Feature: Stop commands
   After you've started a command, you might want to stop a command. To do that
   you've got multiple possibilities.
 
+  On "JRuby" it's not possible to read the output of command which `echo`s a
+  string in a `signal`-handler - `TERM`, `HUP` etc. So please don't write
+  tests, which check on this, if your script needs to run on "JRuby". All other
+  output is logged to `STDERR` and/or `STDOUT` as normal.
+
   Background:
     Given I use a fixture named "cli-app"
 
@@ -15,41 +20,40 @@ Feature: Stop commands
     #!/bin/bash
 
     function term {
-      echo Command1
-      exit 1
+      exit 100
     }
 
     trap term TERM
+    echo "Hello, Aruba!"
     while [ true ]; do sleep 1; done
+    exit 1
     """
     And an executable named "bin/cli2" with:
     """bash
     #!/bin/bash
 
     function term {
-      echo Command2
-      exit 0
+      exit 155
     }
 
     trap term TERM
+    echo "Hello, Aruba!"
     while [ true ]; do sleep 1; done
-    exit 2
+    exit 1
     """
     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 wait 5 seconds for a command to start up
+        Given the default aruba exit timeout is 1 second
+        And I wait 2 seconds for a command to start up
         When I run `cli1` in background
         And I run `cli2` in background
         And I terminate the command started last
-        Then the exit status should be 0
+        Then the exit status should be 155
         And the output should contain:
         \"\"\"
-        Command2
+        Hello, Aruba!
         \"\"\"
     """
     When I run `cucumber`
@@ -66,41 +70,42 @@ Feature: Stop commands
     #!/bin/bash
 
     function term {
-      echo Command1
-      exit 1
+      exit 100
     }
 
     trap term TERM
+    echo "Hello, Aruba!"
     while [ true ]; do sleep 1; done
+    exit 1
     """
     And an executable named "bin/cli2" with:
     """bash
     #!/bin/bash
 
     function term {
-      echo Command2
-      exit 0
+      exit 155
     }
 
     trap term TERM
+    echo "Hello, Aruba!"
     while [ true ]; do sleep 1; done
-    exit 2
+    exit 1
     """
     And a file named "features/stop.feature" with:
     """
     Feature: Run it
       Background:
-        Given the default aruba exit timeout is 5 seconds
 
       Scenario: Run command
-        Given I wait 5 seconds for a command to start up
+        Given the default aruba exit timeout is 5 seconds
+        And I wait 2 seconds for a command to start up
         When I run `cli1` in background
         And I run `cli2` in background
         And I stop the command started last
-        Then the exit status should be 0
+        Then the exit status should be 155
         And the output should contain:
         \"\"\"
-        Command2
+        Hello, Aruba!
         \"\"\"
     """
     When I run `cucumber`
@@ -108,18 +113,19 @@ Feature: Stop commands
 
   Scenario: Terminate command given by commandline
 
-    Terminating a command will send `SIGTERM` to the command.
+    Pass the commandline to the step to find the command, which should be
+    stopped.
 
     Given an executable named "bin/cli1" with:
     """bash
     #!/bin/bash
 
     function term {
-      echo Command1
-      exit 1
+      exit 100
     }
 
     trap term TERM
+    echo "Hello, Aruba!"
     while [ true ]; do sleep 1; done
     """
     And an executable named "bin/cli2" with:
@@ -127,11 +133,11 @@ Feature: Stop commands
     #!/bin/bash
 
     function term {
-      echo Command2
-      exit 0
+      exit 155
     }
 
     trap term TERM
+    echo "Hello, Aruba!"
     while [ true ]; do sleep 1; done
     exit 2
     """
@@ -142,20 +148,20 @@ Feature: Stop commands
         Given the default aruba exit timeout is 5 seconds
 
       Scenario: Run command
-        Given I wait 5 seconds for a command to start up
+        Given I wait 2 seconds for a command to start up
         When I run `cli1` in background
         When I run `cli2` in background
         And I terminate the command "cli1"
-        Then the exit status should be 0
+        Then the exit status should be 100
         And the output should contain:
         \"\"\"
-        Command2
+        Hello, Aruba!
         \"\"\"
     """
     When I run `cucumber`
     Then the features should all pass
 
-  Scenario: Stop last command given by commandline
+  Scenario: Stop 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
@@ -166,25 +172,26 @@ Feature: Stop commands
     #!/bin/bash
 
     function term {
-      echo Command1
-      exit 1
+      exit 155
     }
 
     trap term TERM
+    echo "Hello, Aruba!"
     while [ true ]; do sleep 1; done
+    exit 1
     """
     And an executable named "bin/cli2" with:
     """bash
     #!/bin/bash
 
     function term {
-      echo Command2
-      exit 0
+      exit 100
     }
 
     trap term TERM
+    echo "Hello, Aruba!"
     while [ true ]; do sleep 1; done
-    exit 2
+    exit 1
     """
     And a file named "features/stop.feature" with:
     """
@@ -193,14 +200,14 @@ Feature: Stop commands
         Given the default aruba exit timeout is 5 seconds
 
       Scenario: Run command
-        Given I wait 5 seconds for a command to start up
+        Given I wait 2 seconds for a command to start up
         When I run `cli1` in background
         And I run `cli2` in background
         When I stop the command "cli1"
-        Then the exit status should be 0
+        Then the exit status should be 155
         And the output should contain:
         \"\"\"
-        Command2
+        Hello, Aruba!
         \"\"\"
     """
     When I run `cucumber`
@@ -214,18 +221,18 @@ Feature: Stop commands
     """bash
     #!/bin/bash
     function hup {
-      echo "Exit..."
-      exit 0
+      exit 155
     }
 
     function term {
-      echo "No! No exit here. Try HUP. I stop the command with exit 1."
-      exit 1
+      exit 100
     }
 
     trap hup HUP
     trap term TERM
+    echo "Hello, Aruba!"
     while [ true ]; do sleep 1; done
+    exit 1
     """
     And a file named "features/run.feature" with:
     """
@@ -234,8 +241,73 @@ Feature: Stop commands
         Given the default aruba stop signal is "HUP"
         And the default aruba exit timeout is 5 seconds
         When I run `cli`
-        Then the exit status should be 0
+        Then the exit status should be 155
     """
     When I run `cucumber`
     Then the features should all pass
 
+  @requires-ruby-platform-java
+  Scenario: STDERR/STDOUT is empty on JRUBY if output was written in "signal"-handler
+    Given an executable named "bin/cli1" with:
+    """bash
+    #!/bin/bash
+
+    function term {
+      echo 'Hello, TERM'
+      exit 100
+    }
+
+    trap term TERM
+    echo "Hello, Aruba!"
+    while [ true ]; do sleep 1; done
+    exit 1
+    """
+    And a file named "features/stop.feature" with:
+    """
+    Feature: Run it
+      Scenario: Run command
+        Given the default aruba exit timeout is 1 second
+        And I wait 2 seconds for a command to start up
+        When I run `cli1` in background
+        And I terminate the command started last
+        Then the exit status should be 100
+        And the output should not contain:
+        \"\"\"
+        Hello, TERM
+        \"\"\"
+    """
+    When I run `cucumber`
+    Then the features should all pass
+
+  @requires-ruby-platform-mri
+  Scenario: STDERR/STDOUT is written normally with MRI-Ruby if output was written in "signal"-handler
+    Given an executable named "bin/cli1" with:
+    """bash
+    #!/bin/bash
+
+    function term {
+      echo 'Hello, TERM'
+      exit 100
+    }
+
+    trap term TERM
+    echo "Hello, Aruba!"
+    while [ true ]; do sleep 1; done
+    exit 1
+    """
+    And a file named "features/stop.feature" with:
+    """
+    Feature: Run it
+      Scenario: Run command
+        Given the default aruba exit timeout is 1 second
+        And I wait 2 seconds for a command to start up
+        When I run `cli1` in background
+        And I terminate the command started last
+        Then the exit status should be 100
+        And the output should contain:
+        \"\"\"
+        Hello, TERM
+        \"\"\"
+    """
+    When I run `cucumber`
+    Then the features should all pass

-- 
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