From 34c36a2dc4e93d7ffa65856e2661404fe013b553 Mon Sep 17 00:00:00 2001 From: Ashish Sehra Date: Mon, 21 Mar 2016 21:13:09 +0000 Subject: [PATCH 1/3] Remove the dependency on waitforit --- Gemfile | 1 - Gemfile.lock | 2 -- features/support/command_line.rb | 4 ++-- lib/mirage/client/runner.rb | 18 ++++++++++++++---- mirage.gemspec | 3 --- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index 157d0338..b34bc685 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,6 @@ source 'https://rubygems.org' gem 'sinatra' gem 'childprocess' -gem "waitforit" gem "thor" gem "ptools" gem "httparty" diff --git a/Gemfile.lock b/Gemfile.lock index 3ff01bad..272450c0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -106,7 +106,6 @@ GEM tilt (~> 1.3) thor (0.18.1) tilt (1.4.1) - waitforit (0.0.1) win32-api (1.5.0-x86-mingw32) win32-file (0.6.8) win32-api (>= 1.2.1) @@ -141,4 +140,3 @@ DEPENDENCIES sinatra sinatra-contrib thor - waitforit diff --git a/features/support/command_line.rb b/features/support/command_line.rb index 31708c74..e20bf7ac 100644 --- a/features/support/command_line.rb +++ b/features/support/command_line.rb @@ -8,7 +8,7 @@ def run command process.io.stdout = output process.io.stderr = output process.start - wait_until(:timeout_after => 30.seconds) { process.exited? } + wait_until(:timeout_after => 30) { process.exited? } end File.read(output.path) end @@ -30,4 +30,4 @@ def write_to_file file_path, content end World CommandLine -include CommandLine \ No newline at end of file +include CommandLine diff --git a/lib/mirage/client/runner.rb b/lib/mirage/client/runner.rb index bc541ead..5830b252 100644 --- a/lib/mirage/client/runner.rb +++ b/lib/mirage/client/runner.rb @@ -1,8 +1,8 @@ require 'thor' -require 'waitforit' require 'childprocess' require 'uri' require 'httparty' + module Mirage class << self @@ -30,7 +30,7 @@ def stop options={:port => []} end Runner.new.invoke(:stop, [], options) - rescue ClientError => e + rescue ClientError raise ClientError.new("Mirage is running multiple ports, please specify the port(s) see api/tests for details") end @@ -79,7 +79,7 @@ def start command = command.concat(options.to_a).flatten.collect { |arg| arg.to_s } ChildProcess.build(*command).start - wait_until(:timeout_after => 30.seconds) { Mirage.running?(options) } + wait_until(:timeout_after => 30) { Mirage.running?(options) } begin Mirage::Client.new(options).prime @@ -99,5 +99,15 @@ def stop wait_until { mirage_process_ids(options[:port]).empty? } end + private + + def wait_until(timeout_after: 5, retry_every: 1, &_block) + start_time = Time.now + until Time.now > start_time + timeout_after + return true if yield == true + sleep retry_every + end + fail TimeoutException, 'Action took to long' + end end -end \ No newline at end of file +end diff --git a/mirage.gemspec b/mirage.gemspec index b54da15f..4211cfbc 100644 --- a/mirage.gemspec +++ b/mirage.gemspec @@ -133,7 +133,6 @@ Gem::Specification.new do |s| if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q, [">= 0"]) s.add_runtime_dependency(%q, [">= 0"]) - s.add_runtime_dependency(%q, [">= 0"]) s.add_runtime_dependency(%q, [">= 0"]) s.add_runtime_dependency(%q, [">= 0"]) s.add_runtime_dependency(%q, [">= 0"]) @@ -146,7 +145,6 @@ Gem::Specification.new do |s| else s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) @@ -160,7 +158,6 @@ Gem::Specification.new do |s| else s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) From 5f1e02502058410c35dab1fd70fd47e90bed3e90 Mon Sep 17 00:00:00 2001 From: Ashish Sehra Date: Mon, 21 Mar 2016 21:51:50 +0000 Subject: [PATCH 2/3] Make wait methods available to cucumber --- features/support/command_line.rb | 4 ++++ lib/mirage/client.rb | 3 ++- lib/mirage/client/runner.rb | 12 ++---------- lib/mirage/wait_methods.rb | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 lib/mirage/wait_methods.rb diff --git a/features/support/command_line.rb b/features/support/command_line.rb index e20bf7ac..8b89d762 100644 --- a/features/support/command_line.rb +++ b/features/support/command_line.rb @@ -1,5 +1,9 @@ require 'tempfile' +require 'wait_methods' + module CommandLine + include Mirage::WaitMethods + def run command output = Tempfile.new("child") Dir.chdir SCRATCH do diff --git a/lib/mirage/client.rb b/lib/mirage/client.rb index 0d96cf6e..0b54339b 100644 --- a/lib/mirage/client.rb +++ b/lib/mirage/client.rb @@ -1,4 +1,5 @@ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}" +require 'wait_methods' require 'client/template' require 'client/error' require 'client/cli_bridge' @@ -7,4 +8,4 @@ require 'client/templates' require 'client/requests' require 'client/request' -require 'client/client' \ No newline at end of file +require 'client/client' diff --git a/lib/mirage/client/runner.rb b/lib/mirage/client/runner.rb index 5830b252..d55a4900 100644 --- a/lib/mirage/client/runner.rb +++ b/lib/mirage/client/runner.rb @@ -52,6 +52,8 @@ def running? options_or_url = {:port => 7001} class Runner < Thor include CLIBridge + include Mirage::WaitMethods + RUBY_CMD = ChildProcess.jruby? ? 'jruby' : 'ruby' desc "start", "Starts mirage" @@ -99,15 +101,5 @@ def stop wait_until { mirage_process_ids(options[:port]).empty? } end - private - - def wait_until(timeout_after: 5, retry_every: 1, &_block) - start_time = Time.now - until Time.now > start_time + timeout_after - return true if yield == true - sleep retry_every - end - fail TimeoutException, 'Action took to long' - end end end diff --git a/lib/mirage/wait_methods.rb b/lib/mirage/wait_methods.rb new file mode 100644 index 00000000..661d22b6 --- /dev/null +++ b/lib/mirage/wait_methods.rb @@ -0,0 +1,18 @@ +module Mirage + # module WaitMethods - contains methods for waiting + module WaitMethods + # Wait until a the supplied block returns true + # @example + # wait_until do + # (rand % 2) == 0 + # end + def wait_until(timeout_after: 5, retry_every: 1, &_block) + start_time = Time.now + until Time.now > start_time + timeout_after + return true if yield == true + sleep retry_every + end + fail TimeoutException, 'Action took to long' + end + end +end From f5296a50c89d219e055bee776875b38702c38f6b Mon Sep 17 00:00:00 2001 From: Ashish Sehra Date: Mon, 21 Mar 2016 22:14:02 +0000 Subject: [PATCH 3/3] Drop keywords to continue supporting 1.9 - Bump backports version to avoid "Bad file descriptor" - Also added 2.1.5 to travis config. --- .travis.yml | 3 ++- Gemfile.lock | 2 +- lib/mirage/wait_methods.rb | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 733261d7..c6202df1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ rvm: - '1.9.3' - - '2.0.0' \ No newline at end of file + - '2.0.0' + - '2.1.5' diff --git a/Gemfile.lock b/Gemfile.lock index 272450c0..9e4bcc66 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ GEM remote: https://rubygems.org/ specs: addressable (2.3.5) - backports (3.3.5) + backports (3.6.8) bouncy-castle-java (1.5.0147) builder (3.2.2) childprocess (0.3.9) diff --git a/lib/mirage/wait_methods.rb b/lib/mirage/wait_methods.rb index 661d22b6..9d5ec7cd 100644 --- a/lib/mirage/wait_methods.rb +++ b/lib/mirage/wait_methods.rb @@ -6,11 +6,12 @@ module WaitMethods # wait_until do # (rand % 2) == 0 # end - def wait_until(timeout_after: 5, retry_every: 1, &_block) + def wait_until(opts = {}) + opts = {timeout_after: 5, retry_every: 0.1}.merge(opts) start_time = Time.now - until Time.now > start_time + timeout_after + until Time.now > start_time + opts[:timeout_after] return true if yield == true - sleep retry_every + sleep opts[:retry_every] end fail TimeoutException, 'Action took to long' end