Skip to content

Commit

Permalink
Merge in calabash#148, bet let DEVICE_TARGET be the UDID for the devi…
Browse files Browse the repository at this point in the history
…ce. Fix a bug where calabash_exit causes errors when running device
  • Loading branch information
krukow committed May 13, 2013
1 parent 6b71ac0 commit bbf65ad
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
4 changes: 3 additions & 1 deletion calabash-cucumber/features-skeleton/support/01_launch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@

at_exit do
launcher = Calabash::Cucumber::Launcher.new
Calabash::Cucumber::SimulatorHelper.stop unless launcher.calabash_no_stop?
if launcher.simulator_target?
Calabash::Cucumber::SimulatorHelper.stop unless launcher.calabash_no_stop?
end
end
34 changes: 15 additions & 19 deletions calabash-cucumber/lib/calabash-cucumber/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ module Core

DATA_PATH = File.expand_path(File.dirname(__FILE__))
CAL_HTTP_RETRY_COUNT=3
RETRYABLE_ERRORS = [Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::ETIMEDOUT]
RETRYABLE_ERRORS = [HTTPClient::TimeoutError,
HTTPClient::KeepAliveDisconnected,
Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ECONNABORTED,
Errno::ETIMEDOUT]

def macro(txt)
if self.respond_to? :step
Expand Down Expand Up @@ -466,10 +469,11 @@ def backdoor(sel, arg)

def calabash_exit
# Exiting the app shuts down the HTTP connection and generates ECONNREFUSED,
# or HTTPClient::KeepAliveDisconnected
# which needs to be suppressed.
begin
http({:method =>:post, :path => 'exit', :retryable_errors => RETRYABLE_ERRORS - [Errno::ECONNREFUSED]})
rescue Errno::ECONNREFUSED
http({:method =>:post, :path => 'exit', :retryable_errors => RETRYABLE_ERRORS - [Errno::ECONNREFUSED,HTTPClient::KeepAliveDisconnected]})
rescue Errno::ECONNREFUSED, HTTPClient::KeepAliveDisconnected
[]
end
end
Expand Down Expand Up @@ -548,6 +552,7 @@ def url_for(verb)
end

def make_http_request(options)

body = nil
retryable_errors = options[:retryable_errors] || RETRYABLE_ERRORS
CAL_HTTP_RETRY_COUNT.times do |count|
Expand All @@ -561,29 +566,20 @@ def make_http_request(options)
body = @http.get(options[:uri], options[:body]).body
end
break
rescue HTTPClient::TimeoutError, HTTPClient::KeepAliveDisconnected => e
if count < CAL_HTTP_RETRY_COUNT-1
@http.reset_all
@http=nil
STDOUT.write "Waiting 5 secs before retry...\n"
sleep(5)
STDOUT.write "Retrying.. #{e.class}: (#{e})\n"
STDOUT.flush
rescue Exception => e

else
puts "Failing... #{e.class}"
raise e
end
if retryable_errors.include?(e) || retryable_errors.any?{|c| e.is_a?(c)}

rescue Exception => e
if retryable_errors.include?(e)
if count < CAL_HTTP_RETRY_COUNT-1
sleep(0.5)
if e.is_a?(HTTPClient::TimeoutError)
sleep(3)
else
sleep(0.5)
end
@http.reset_all
@http=nil
STDOUT.write "Retrying.. #{e.class}: (#{e})\n"
STDOUT.flush

else
puts "Failing... #{e.class}"
raise e
Expand Down
7 changes: 5 additions & 2 deletions calabash-cucumber/lib/calabash-cucumber/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def calabash_no_launch?
end

def device_target?
ENV['DEVICE_TARGET'] == 'device'
(ENV['DEVICE_TARGET'] != nil) && (not simulator_target?)
end

def simulator_target?
Expand Down Expand Up @@ -68,7 +68,10 @@ def relaunch(args={})

if device_target?
default_args = {:app => ENV['BUNDLE_ID']}
default_args[:udid] = ENV['UDID_TARGET'] if ENV['UDID_TARGET']
target = ENV['DEVICE_TARGET']
if target != 'DEVICE'
default_args[:udid] = target
end
self.run_loop = RunLoop.run(default_args.merge(args))
else

Expand Down
4 changes: 2 additions & 2 deletions calabash-cucumber/lib/calabash-cucumber/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Calabash
module Cucumber
VERSION = '0.9.145.pre2'
FRAMEWORK_VERSION = '0.9.145.pre2'
VERSION = '0.9.145.pre3'
FRAMEWORK_VERSION = '0.9.145.pre3'
end
end

0 comments on commit bbf65ad

Please sign in to comment.