Logo: Relish

  1. Sign in

Project: Aruba 0.11.0

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 echos 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"
Scenarios
Terminate last command started

Terminating a command will send SIGTERM to the command.

Given
an executable named "bin/cli1" with:
#!/bin/bash

function term {
  exit 100
}

trap term TERM
echo "Hello, Aruba!"
while [ true ]; do sleep 1; done
exit 1
And
an executable named "bin/cli2" with:
#!/bin/bash

function term {
  exit 155
}

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 run cli2 in background
    And I terminate the command started last
    Then the exit status should be 155
    And the output should contain:
    """
    Hello, Aruba!
    """
When
I run cucumber
Then
the features should all pass
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:
#!/bin/bash

function term {
  exit 100
}

trap term TERM
echo "Hello, Aruba!"
while [ true ]; do sleep 1; done
exit 1
And
an executable named "bin/cli2" with:
#!/bin/bash

function term {
  exit 155
}

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

  Scenario: Run command
    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 155
    And the output should contain:
    """
    Hello, Aruba!
    """
When
I run cucumber
Then
the features should all pass
Terminate command given by commandline

Pass the commandline to the step to find the command, which should be
stopped.

Given
an executable named "bin/cli1" with:
#!/bin/bash

function term {
  exit 100
}

trap term TERM
echo "Hello, Aruba!"
while [ true ]; do sleep 1; done
And
an executable named "bin/cli2" with:
#!/bin/bash

function term {
  exit 155
}

trap term TERM
echo "Hello, Aruba!"
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 5 seconds

  Scenario: Run command
    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 100
    And the output should contain:
    """
    Hello, Aruba!
    """
When
I run cucumber
Then
the features should all pass
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
timeout of aruba.

Given
an executable named "bin/cli1" with:
#!/bin/bash

function term {
  exit 155
}

trap term TERM
echo "Hello, Aruba!"
while [ true ]; do sleep 1; done
exit 1
And
an executable named "bin/cli2" with:
#!/bin/bash

function 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
  Background:
    Given the default aruba exit timeout is 5 seconds

  Scenario: Run command
    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 155
    And the output should contain:
    """
    Hello, Aruba!
    """
When
I run cucumber
Then
the features should all pass
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:
#!/bin/bash
function hup {
  exit 155
}

function term {
  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:
Feature: Run it
  Scenario: Run command
    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 155
When
I run cucumber
Then
the features should all pass
  • @requires-ruby-platform-java
STDERR/STDOUT is empty on JRUBY if output was written in "signal"-handler
Given
an executable named "bin/cli1" with:
#!/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
STDERR/STDOUT is written normally with MRI-Ruby if output was written in "signal"-handler
Given
an executable named "bin/cli1" with:
#!/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

Last published about 6 years ago by Max Meyer.