X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/8a6c7aa5eac21e93d721bf958ca67eb7f216888e..6b3cfe60beb46ba087de5093926363d8b03ab889:/apps/workbench/test/integration_helper.rb diff --git a/apps/workbench/test/integration_helper.rb b/apps/workbench/test/integration_helper.rb index 74072caaad..ef2779cc3e 100644 --- a/apps/workbench/test/integration_helper.rb +++ b/apps/workbench/test/integration_helper.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'test_helper' require 'capybara/rails' require 'capybara/poltergeist' @@ -5,10 +9,20 @@ require 'uri' require 'yaml' def available_port for_what - Addrinfo.tcp("0.0.0.0", 0).listen do |srv| - port = srv.connect_address.ip_port - STDERR.puts "Using port #{port} for #{for_what}" - return port + begin + Addrinfo.tcp("0.0.0.0", 0).listen do |srv| + port = srv.connect_address.ip_port + # Selenium needs an additional locking port, check if it's available + # and retry if necessary. + if for_what == 'selenium' + locking_port = port - 1 + Addrinfo.tcp("0.0.0.0", locking_port).listen.close + end + STDERR.puts "Using port #{port} for #{for_what}" + return port + end + rescue Errno::EADDRINUSE, Errno::EACCES + retry end end @@ -34,6 +48,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]) @@ -56,16 +75,24 @@ Capybara.register_driver :selenium_with_download do |app| end module WaitForAjax - Capybara.default_max_wait_time = 5 + # 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 @@ -126,6 +153,19 @@ module HeadlessHelper end end +module KeepWebConfig + def getport service + File.read(File.expand_path("../../../../tmp/#{service}.port", __FILE__)) + end + + def use_keep_web_config + @kwport = getport 'keep-web-ssl' + @kwdport = getport 'keep-web-dl-ssl' + Rails.configuration.keep_web_url = "https://localhost:#{@kwport}/c=%{uuid_or_pdh}" + Rails.configuration.keep_web_download_url = "https://localhost:#{@kwdport}/c=%{uuid_or_pdh}" + end +end + class ActionDispatch::IntegrationTest # Make the Capybara DSL available in all integration tests include Capybara::DSL @@ -184,4 +224,35 @@ class ActionDispatch::IntegrationTest end Capybara.reset_sessions! end + + def accept_alert + if Capybara.current_driver == :selenium + (0..9).each do + begin + page.driver.browser.switch_to.alert.accept + break + rescue Selenium::WebDriver::Error::NoSuchAlertError + sleep 0.1 + end + end + else + # poltergeist returns true for confirm, so no need to accept + end + end +end + +def upload_data_and_get_collection(data, user, filename, owner_uuid=nil) + token = api_fixture('api_client_authorizations')[user]['api_token'] + datablock = `echo -n #{data.shellescape} | ARVADOS_API_TOKEN=#{token.shellescape} arv-put --no-progress --raw -`.strip + assert $?.success?, $? + col = nil + use_token user do + mtxt = ". #{datablock} 0:#{data.length}:#{filename}\n" + if owner_uuid + col = Collection.create(manifest_text: mtxt, owner_uuid: owner_uuid) + else + col = Collection.create(manifest_text: mtxt) + end + end + return col end