Draft: Use helper to turn on elasticsearch once for end to end tests
What does this MR do and why?
Before this change we check to see if elasticsearch is turned on, and if not, we turn it on and wait before each test class. Furthermore, after each test class we were checking if the original state was off, and if so we'd return the system under test to it's original off state.
Because our CI test containers spin up with elasticsearch turned off, this made of inefficient test runs as we'd be turning elasticsearch on and off and waiting frequently. In this MR we check to see if elasticsearch is turned on before any of the test classes run and if it is not turned on, we turn it on. As a side effect, elasticsearch is left on after the tests execute. I don't believe this is a big problem since the container is destroyed afterwards anyway, and, for local runs, if you're running elasticsearch tests you probably want elasticsearch turned on anyway.
Originally my plan was to use a global variable to store the original on-state of elasticsearch and then return to that original state in an after(:suite)
step, but that required the use of a class variables which the linter did not like. This was my original idea:
# frozen_string_literal: true
require_relative '../qa'
@@elastic_original_state_on = QA::Runtime::Search.elasticsearch_on?(QA::Runtime::API::Client.as_admin)
RSpec.configure do |config|
config.before(:suite) do
unless @@elastic_original_state_on
QA::EE::Resource::Settings::Elasticsearch.fabricate_via_api!
end
end
config.after(:suite) do
unless @@elastic_original_state_on
QA::Runtime::Search.disable_elasticsearch(QA::Runtime::API::Client.as_admin)
end
end
end
But in the spirit of getting something that works as a first iteration, I'm just turning on elasticsearch if it's not on, and leaving it on afterwards.
By using Chloe's suggestion below I am able to properly turn on and off elasticsearch.
Closes #337158 (closed)
Screenshots or screen recordings
How to set up and validate locally
- Follow the elasticsearch setup steps here https://gitlab.com/gitlab-org/gitlab-development-kit/-/blob/main/doc/howto/elasticsearch.md
- Call the test against gdk like so:
BROWSER_HEADLESS=false QA_DEBUG=true bundle exec bin/qa Test::Instance::All http://<your.gdk.url>/ -- qa/specs/features/ee/api/enablement/elasticsearch --tag orchestrated --tag elasticsearch --tag requires_admin
Optionally, you can turn elasticsearch off in Admin Area -> Settings -> Advanced Search by unchecking theElasticsearch indexing
checkbox andSearch with Elasticsearch enabled
checkbox, save your changes, then run the test again to see that the test turns these checkboxes back on after the test begins executing.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.