diff --git a/qa/qa/tools/readiness_check.rb b/qa/qa/tools/readiness_check.rb index ed6962d0f1c4573dfd48f09e0f4299c374cedb0f..697d512be604667b9943cb921e1753e5359c51d4 100644 --- a/qa/qa/tools/readiness_check.rb +++ b/qa/qa/tools/readiness_check.rb @@ -9,6 +9,8 @@ module Tools class ReadinessCheck include Support::API + ReadinessCheckError = Class.new(StandardError) + def self.perform(wait: 60) new(wait: wait).perform end @@ -21,22 +23,14 @@ def initialize(wait:) # # @return [void] def perform - error = nil - info("Waiting for Gitlab to become ready!") - Support::Retrier.retry_until(max_duration: wait, sleep_interval: 1, raise_on_failure: false, log: false) do - result = !required_elements_missing? - error = nil + debug("Checking required element presence on sign-in page") - result - rescue StandardError => e - error = "#{error_base} #{e.message}" - - false - end - raise error if error + wait_for_login_page_to_load info("Gitlab is ready!") + rescue StandardError => e + raise ReadinessCheckError, "#{error_base} Reason: #{e}" end private @@ -66,40 +60,23 @@ def elements_css @element_css ||= QA::Page::Main::Login.elements.select(&:required?).map(&:selector_css) end - # Check for missing required elements on sign-in page + # Check if sign_in page loads with all required elements # - # @return [Boolean] - def required_elements_missing? - debug("Checking for required element presence on '#{url}'") + # @return [void] + def wait_for_login_page_to_load # Do not perform headless request on .com due to cloudfare - return rendered_elements_missing? if Runtime::Env.running_on_dot_com? - - response = get(url) - - unless ok_response?(response) - msg = "Got unsucessfull response code: #{response.code}" - debug(msg) && raise(msg) + if Runtime::Env.running_on_dot_com? + debug("Checking for required elements via web browser") + return Capybara.current_session.using_wait_time(wait) { Runtime::Browser.visit(:gitlab, Page::Main::Login) } end - unless required_elements_present?(response) - msg = "Sign in page missing required elements: '#{elements_css}'" - debug(msg) && raise(msg) - end + Support::Retrier.retry_on_exception(max_attempts: wait, sleep_interval: 1, log: false) do + response = get(url) + raise "Got unsucessfull response code from #{url}: #{response.code}" unless ok_response?(response) + raise "Sign in page missing required elements: '#{elements_css}'" unless required_elements_present?(response) + end debug("Required elements are present!") - false - end - - # Perform check for present elements via web browser - # - # @return [Boolean] - def rendered_elements_missing? - debug("Checking for required elements via web browser") - Runtime::Browser.visit(:gitlab, Page::Main::Login) - false - rescue StandardError => e - debug("Sign in page did not render fully") - raise(e) end # Validate response code is 200 diff --git a/qa/spec/tools/readiness_check_spec.rb b/qa/spec/tools/readiness_check_spec.rb index 75c7e1290f9d4c707719fb759a5cbeca55659114..a1e943e045a719e5bece121eed2011531b393b57 100644 --- a/qa/spec/tools/readiness_check_spec.rb +++ b/qa/spec/tools/readiness_check_spec.rb @@ -5,7 +5,7 @@ let(:url) { "example.com" } let(:wait) { 1 } - let(:msg_base) { "Gitlab readiness check failed, valid sign_in page did not appear within #{wait} seconds!" } + let(:msg_base) { "Gitlab readiness check failed, valid sign_in page did not appear within #{wait} seconds! Reason:" } let(:dot_com) { false } let(:response) { instance_double(RestClient::Response, code: code, body: body) } @@ -13,6 +13,7 @@ let(:body) { "" } before do + allow(Capybara).to receive_message_chain("current_session.using_wait_time").and_yield allow(QA::Runtime::Env).to receive(:running_on_dot_com?).and_return(dot_com) allow(QA::Support::GitlabAddress).to receive(:address_with_port).with(with_default_port: false).and_return(url) allow(readiness_check).to receive(:get).with("#{url}/users/sign_in").and_return(response) @@ -51,7 +52,7 @@ it "raises an error on validation" do expect { readiness_check.perform }.to raise_error( - "#{msg_base} Got unsucessfull response code: #{code}" + "#{msg_base} Got unsucessfull response code from #{url}/users/sign_in: #{code}" ) end end