[DRE-commits] [ruby-aruba] 09/74: Add startup wait time to help slow processes to startup before going on
Hideki Yamane
henrich at moszumanska.debian.org
Sat Nov 28 01:16:28 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 e686fd2f5401bf27cb28468415020358a82d477a
Author: Max Meyer <dev at fedux.org>
Date: Mon Nov 23 16:35:26 2015 +0100
Add startup wait time to help slow processes to startup before going on
---
History.md | 20 +++++-----
features/api/command/send_signal.feature | 4 +-
features/configuration/startup_wait_time.feature | 48 ++++++++++++++++++++++++
lib/aruba/api/command.rb | 6 ++-
lib/aruba/command.rb | 3 +-
lib/aruba/config.rb | 1 +
lib/aruba/processes/basic_process.rb | 5 ++-
lib/aruba/processes/in_process.rb | 2 +-
lib/aruba/processes/spawn_process.rb | 3 +-
9 files changed, 73 insertions(+), 19 deletions(-)
diff --git a/History.md b/History.md
index 5afe172..469ec67 100644
--- a/History.md
+++ b/History.md
@@ -1,18 +1,10 @@
# Latest Release
-## [v0.11.0](https://github.com/cucumber/aruba/compare/v0.10.2...v0.11.0)
-
-* Set stop signal which should be used to stop a process after a timeout or
- used to terminate a process. This can be used to stop processes running
- docker + "systemd". If you send a systemd-enable container SIGINT it will be
- stopped.
-
-# Old releases
-
## [v0.10.2](https://github.com/cucumber/aruba/compare/v0.10.1...v0.10.2)
* Fixed problem in regex after merge of step definitions
+# Old releases
## [v0.10.1](https://github.com/cucumber/aruba/compare/v0.10.0...v0.10.1)
@@ -438,6 +430,16 @@
# Upcoming un-released versions
+## [v0.11.0](https://github.com/cucumber/aruba/compare/v0.10.2...v0.11.0)
+
+* Set stop signal which should be used to stop a process after a timeout or
+ used to terminate a process. This can be used to stop processes running
+ docker + "systemd". If you send a systemd-enable container SIGINT it will be
+ stopped.
+* Added a configurable amount of time after a command was started -
+ startup_wait_time. Otherwise you get problems when a process takes to long to
+ startup when you run in background and want to sent it a signal.
+
## [v1.0.0](https://github.com/cucumber/aruba/compare/v0.11.0...v1.0.0)
* Support for rubies older than 1.9.3 is discontinued - e.g 1.8.7 and 1.9.2
diff --git a/features/api/command/send_signal.feature b/features/api/command/send_signal.feature
index fbd9fec..a2f471b 100644
--- a/features/api/command/send_signal.feature
+++ b/features/api/command/send_signal.feature
@@ -22,11 +22,9 @@ Feature: Send running command a signal
"""ruby
require 'spec_helper'
- RSpec.describe 'Run command', :type => :aruba, :exit_timeout => 3 do
+ RSpec.describe 'Run command', :type => :aruba, :exit_timeout => 3, :startup_wait_time => 2 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
"""
diff --git a/features/configuration/startup_wait_time.feature b/features/configuration/startup_wait_time.feature
new file mode 100644
index 0000000..be57a10
--- /dev/null
+++ b/features/configuration/startup_wait_time.feature
@@ -0,0 +1,48 @@
+Feature: Set time to wait after spawning command
+
+ As a developer
+ I want to configure a time span to wait after the command was spawned
+ In order to prevent failure of some commands which take a little bit longer
+ to load.
+
+
+ If you setup a ruby script, this may load bundler. This makes the script to
+ start up a little bit longer. If you want to run a command in background,
+ starting the command in a background process may take longer then sending it
+ a signal.
+
+ If you experience some brittle tests with background commands, try to set the
+ `#startup_wait_time`.
+
+ Background:
+ Given I use the fixture "cli-app"
+
+ Scenario: Default value
+ Given a file named "features/support/aruba.rb" with:
+ """ruby
+ Aruba.configure do |config|
+ puts %(The default value is "#{config.startup_wait_time}")
+ end
+ """
+ When I successfully run `cucumber`
+ Then the output should contain:
+ """
+ The default value is "0"
+ """
+
+ Scenario: Modify value
+ Given a file named "features/support/aruba.rb" with:
+ """ruby
+ Aruba.configure do |config|
+ config.startup_wait_time = 2
+ end
+
+ Aruba.configure do |config|
+ puts %(The default value is "#{config.startup_wait_time}")
+ end
+ """
+ Then I successfully run `cucumber`
+ Then the output should contain:
+ """
+ The default value is "0"
+ """
diff --git a/lib/aruba/api/command.rb b/lib/aruba/api/command.rb
index 223958c..ae899bb 100644
--- a/lib/aruba/api/command.rb
+++ b/lib/aruba/api/command.rb
@@ -130,10 +130,11 @@ module Aruba
#
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity
- def run(cmd, exit_timeout = nil, io_wait_timeout = nil, stop_signal = nil)
+ def run(cmd, exit_timeout = nil, io_wait_timeout = nil, stop_signal = nil, startup_wait_time = nil)
exit_timeout ||= aruba.config.exit_timeout
io_wait_timeout ||= aruba.config.io_wait_timeout
stop_signal ||= aruba.config.stop_signal
+ startup_wait_time ||= aruba.config.startup_wait_time
@commands ||= []
@commands << cmd
@@ -175,7 +176,8 @@ module Aruba
:working_directory => working_directory,
:environment => environment,
:main_class => main_class,
- :stop_signal => stop_signal
+ :stop_signal => stop_signal,
+ :startup_wait_time => startup_wait_time
)
if aruba.config.before? :cmd
diff --git a/lib/aruba/command.rb b/lib/aruba/command.rb
index b5891c0..99fcb64 100644
--- a/lib/aruba/command.rb
+++ b/lib/aruba/command.rb
@@ -19,7 +19,8 @@ module Aruba
opts.fetch(:working_directory),
opts.fetch(:environment),
opts.fetch(:main_class),
- opts.fetch(:stop_signal)
+ opts.fetch(:stop_signal),
+ opts.fetch(:startup_wait_time)
)
rescue KeyError => e
raise ArgumentError, e.message
diff --git a/lib/aruba/config.rb b/lib/aruba/config.rb
index f335f78..e01a2b5 100644
--- a/lib/aruba/config.rb
+++ b/lib/aruba/config.rb
@@ -31,6 +31,7 @@ module Aruba
option_accessor :exit_timeout, :contract => { Num => Num }, :default => 15
option_accessor :stop_signal, :contract => { Maybe[String] => Maybe[String] }, :default => nil
option_accessor :io_wait_timeout, :contract => { Num => Num }, :default => 0.1
+ option_accessor :startup_wait_time, :contract => { Num => Num }, :default => 0
option_accessor :fixtures_directories, :contract => { Array => ArrayOf[String] }, :default => %w(features/fixtures spec/fixtures test/fixtures fixtures)
option_accessor :command_runtime_environment, :contract => { Hash => Hash }, :default => ENV.to_hash.dup
# rubocop:disable Metrics/LineLength
diff --git a/lib/aruba/processes/basic_process.rb b/lib/aruba/processes/basic_process.rb
index 478a067..a7968b2 100644
--- a/lib/aruba/processes/basic_process.rb
+++ b/lib/aruba/processes/basic_process.rb
@@ -4,15 +4,16 @@ require 'shellwords'
module Aruba
module Processes
class BasicProcess
- attr_reader :exit_status, :environment
+ attr_reader :exit_status, :environment, :startup_wait_time
- def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil)
+ def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil, startup_wait_time = 0)
@cmd = cmd
@working_directory = working_directory
@environment = environment
@main_class = main_class
@exit_status = nil
@stop_signal = stop_signal
+ @startup_wait_time = startup_wait_time
@exit_timeout = exit_timeout
@io_wait = io_wait
diff --git a/lib/aruba/processes/in_process.rb b/lib/aruba/processes/in_process.rb
index 3db943c..3b6fdf9 100644
--- a/lib/aruba/processes/in_process.rb
+++ b/lib/aruba/processes/in_process.rb
@@ -33,7 +33,7 @@ module Aruba
# @private
attr_reader :main_class
- def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil)
+ def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil, startup_wait_time = 0)
@cmd = cmd
@argv = arguments
@stdin = StringIO.new
diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb
index a529bea..c3e7c6d 100644
--- a/lib/aruba/processes/spawn_process.rb
+++ b/lib/aruba/processes/spawn_process.rb
@@ -27,7 +27,7 @@ module Aruba
#
# @params [String] working_directory
# The directory where the command will be executed
- def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil)
+ def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil, startup_wait_time = 0)
super
@process = nil
@@ -75,6 +75,7 @@ module Aruba
begin
Aruba.platform.with_environment(environment) do
@process.start
+ sleep startup_wait_time
end
rescue ChildProcess::LaunchError => e
raise LaunchError, "It tried to start #{cmd}. " + e.message
--
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