Commit de7b6a47 authored by Mark Lapierre's avatar Mark Lapierre

Wait for elasticsearch server before searching

Checks for a valid search response via the API using an
elasticsearch-only scope. Checks 3 times and raises an exception if
unable to search.

This gives the elasticsearch server time to be ready for the the
index to be created before the first test.

Waiting for a response takes time, so it should be enough to make 3
attempts with the default interval between attempts.
parent 3708e662
......@@ -36,6 +36,7 @@ module QA
autoload :GPG, 'qa/runtime/gpg'
autoload :MailHog, 'qa/runtime/mail_hog'
autoload :IPAddress, 'qa/runtime/ip_address'
autoload :Search, 'qa/runtime/search'
module API
autoload :Client, 'qa/runtime/api/client'
......
# frozen_string_literal: true
module QA
module Runtime
module Search
extend self
extend Support::Api
ElasticSearchServerError = Class.new(RuntimeError)
def elasticsearch_responding?
QA::Runtime::Logger.debug("Attempting to search via Elasticsearch...")
QA::Support::Retrier.retry_on_exception do
# We don't care about the results of the search, we just need
# any search that uses Elasticsearch, not the native search
# The Elasticsearch-only scopes are blobs, wiki_blobs, and commits.
request = Runtime::API::Request.new(api_client, "/search?scope=blobs&search=foo")
response = get(request.url)
unless response.code == singleton_class::HTTP_STATUS_OK
raise ElasticSearchServerError, "Search attempt failed. Request returned (#{response.code}): `#{response}`."
end
true
end
end
private
def api_client
@api_client ||= Runtime::API::Client.new(:gitlab)
end
end
end
end
......@@ -17,6 +17,8 @@ module QA
es.api_client = Runtime::API::Client.as_admin
end
Runtime::Search.elasticsearch_responding?
@project = Resource::Project.fabricate_via_api! do |project|
project.add_name_uuid = false
project.name = "es-adv-global-search-#{project_name_suffix}1"
......@@ -50,6 +52,7 @@ module QA
Page::Search::Results.perform do |results|
results.switch_to_projects
expect(results).to have_content("Advanced search functionality is enabled")
expect(results).to have_project(@project.name)
end
end
......
......@@ -14,6 +14,8 @@ module QA
QA::EE::Resource::Settings::Elasticsearch.fabricate_via_browser_ui!
end
Runtime::Search.elasticsearch_responding?
@project = Resource::Project.fabricate_via_api! do |project|
project.name = project_name
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment