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 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..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) @@ -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..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 @@ -8,7 +12,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 +34,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.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 bc541ead..d55a4900 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 @@ -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" @@ -79,7 +81,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 @@ -100,4 +102,4 @@ def stop end end -end \ No newline at end of file +end diff --git a/lib/mirage/wait_methods.rb b/lib/mirage/wait_methods.rb new file mode 100644 index 00000000..9d5ec7cd --- /dev/null +++ b/lib/mirage/wait_methods.rb @@ -0,0 +1,19 @@ +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(opts = {}) + opts = {timeout_after: 5, retry_every: 0.1}.merge(opts) + start_time = Time.now + until Time.now > start_time + opts[:timeout_after] + return true if yield == true + sleep opts[:retry_every] + end + fail TimeoutException, 'Action took to long' + end + end +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"])