summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRubén Dávila <rdavila84@gmail.com>2015-12-27 21:43:59 -0500
committerRubén Dávila <rdavila84@gmail.com>2015-12-27 21:43:59 -0500
commite1acf12a2d9e59e74e7e5ce729e678da2c6b9e26 (patch)
tree3a75e63e9ffa85db33dd1b5d69a6fc7f319e614c
parentc61aec82191f71cab697d36dc701894ee79d613e (diff)
downloadgitlab-ce-issue_4662.tar.gz
Restart PhantomJS on timeout errors. #4662issue_4662
-rw-r--r--spec/support/capybara_helpers.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/support/capybara_helpers.rb b/spec/support/capybara_helpers.rb
index 9b5c3065eed..a8ba786c130 100644
--- a/spec/support/capybara_helpers.rb
+++ b/spec/support/capybara_helpers.rb
@@ -29,6 +29,37 @@ module CapybaraHelpers
end
end
+# See: https://github.com/teampoltergeist/poltergeist/issues/375#issuecomment-54171533
+def restart_phantomjs
+ puts "-> Restarting phantomjs: iterating through capybara sessions..."
+ session_pool = Capybara.send('session_pool')
+ session_pool.each do |mode,session|
+ msg = " => #{mode} -- "
+ driver = session.driver
+ if driver.is_a?(Capybara::Poltergeist::Driver)
+ msg += "restarting"
+ driver.restart
+ else
+ msg += "not poltergeist: #{driver.class}"
+ end
+ puts msg
+ end
+end
+
+CAPYBARA_TIMEOUT_RETRIES = 3
+
RSpec.configure do |config|
config.include CapybaraHelpers, type: :feature
+
+ config.around(:each, type: :feature) do |ex|
+ example = RSpec.current_example
+ CAPYBARA_TIMEOUT_RETRIES.times do |i|
+ example.instance_variable_set('@exception', nil)
+ self.instance_variable_set('@__memoized', nil) # clear let variables
+ ex.run
+ break unless example.exception.is_a?(Capybara::Poltergeist::TimeoutError)
+ puts("\nCapybara::Poltergeist::TimeoutError at #{example.location}\n Restarting phantomjs and retrying...")
+ restart_phantomjs
+ end
+ end
end