Merge branch 'master' into 10172-crunch2-container-output
[arvados.git] / apps / workbench / test / integration_helper.rb
index c133de0d6b16ef821e3c44dbb8357991b3de2dda..3d92585135ff3db934c78cc6a092bf74a8b39054 100644 (file)
@@ -17,7 +17,7 @@ def available_port for_what
       STDERR.puts "Using port #{port} for #{for_what}"
       return port
     end
-  rescue Errno::EADDRINUSE => e
+  rescue Errno::EADDRINUSE, Errno::EACCES
     retry
   end
 end
@@ -44,6 +44,11 @@ Capybara.register_driver :poltergeist_debug do |app|
   Capybara::Poltergeist::Driver.new app, poltergeist_opts.merge(inspector: true)
 end
 
+Capybara.register_driver :poltergeist_with_fake_websocket do |app|
+  js = File.expand_path '../support/fake_websocket.js', __FILE__
+  Capybara::Poltergeist::Driver.new app, poltergeist_opts.merge(extensions: [js])
+end
+
 Capybara.register_driver :poltergeist_without_file_api do |app|
   js = File.expand_path '../support/remove_file_api.js', __FILE__
   Capybara::Poltergeist::Driver.new app, poltergeist_opts.merge(extensions: [js])
@@ -66,16 +71,24 @@ Capybara.register_driver :selenium_with_download do |app|
 end
 
 module WaitForAjax
+  # FIXME: Huge side effect here
+  # The following line changes the global default Capybara wait time, affecting
+  # every test which follows this one. This should be removed and the failing tests
+  # should have their individual wait times increased, if appropriate, using
+  # the using_wait_time(N) construct to temporarily change the wait time.
+  # Note: the below is especially bad because there are places that increase wait
+  # times using a multiplier e.g. using_wait_time(3 * Capybara.default_max_wait_time)
   Capybara.default_max_wait_time = 10
   def wait_for_ajax
-    Timeout.timeout(Capybara.default_max_wait_time) do
-      loop until finished_all_ajax_requests?
+    timeout = 10
+    count = 0
+    while page.evaluate_script("jQuery.active").to_i > 0
+      count += 1
+      raise "AJAX request took more than #{timeout} seconds" if count > timeout * 10
+      sleep(0.1)
     end
   end
 
-  def finished_all_ajax_requests?
-    page.evaluate_script('jQuery.active').zero?
-  end
 end
 
 module AssertDomEvent