Commit a981515d authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '6481-use-elasticsearch-indexer-in-specs' into 'master'

Use the Golang elasticsearch indexer in tests

See merge request gitlab-org/gitlab-ee!12680
parents 02a368b3 c12754cc
......@@ -12,8 +12,14 @@ module Gitlab
Error = Class.new(StandardError)
def self.experimental_indexer_present?
Gitlab::Utils.which(EXPERIMENTAL_INDEXER).present?
class << self
def experimental_indexer_present?
Gitlab::Utils.which(EXPERIMENTAL_INDEXER).present?
end
def experimental_indexer_version
Rails.root.join('GITLAB_ELASTICSEARCH_INDEXER_VERSION').read.chomp
end
end
attr_reader :project, :index_status
......
namespace :gitlab do
namespace :indexer do
desc "GitLab | Install or upgrade gitlab-elasticsearch-indexer"
task :install, [:dir, :repo] => :gitlab_environment do |t, args|
unless args.dir.present?
abort %(Please specify the directory where you want to install the indexer
Usage: rake "gitlab:indexer:install[/installation/dir,repo]")
end
args.with_defaults(repo: 'https://gitlab.com/gitlab-org/gitlab-elasticsearch-indexer.git')
version = Gitlab::Elastic::Indexer.experimental_indexer_version
make = Gitlab::Utils.which('gmake') || Gitlab::Utils.which('make')
abort "Couldn't find a 'make' binary" unless make
checkout_or_clone_version(version: version, repo: args.repo, target_dir: args.dir)
Dir.chdir(args.dir) { run_command!([make, 'build']) }
end
end
end
......@@ -31,7 +31,7 @@ describe Git::BranchPushService do
end
end
context 'ElasticSearch indexing' do
context 'ElasticSearch indexing', :elastic do
before do
stub_ee_application_setting(elasticsearch_indexing?: true)
end
......
RSpec.configure do |config|
config.before(:each, :elastic) do
stub_ee_application_setting(elasticsearch_experimental_indexer: true)
Gitlab::Elastic::Helper.create_empty_index
end
......
# frozen_string_literal: true
module EE
module TestEnv
def init(*args, &blk)
super
setup_indexer
end
def setup_indexer
indexer_args = [indexer_path, indexer_url].compact.join(',')
component_timed_setup(
'GitLab Elasticsearch Indexer',
install_dir: indexer_path,
version: indexer_version,
task: "gitlab:indexer:install[#{indexer_args}]"
)
ENV['PATH'] = # rubocop:disable RSpec/EnvAssignment
[indexer_bin_path, ENV['PATH']].join(File::PATH_SEPARATOR)
end
def indexer_path
@indexer_path ||= File.join('tmp', 'tests', 'gitlab-elasticsearch-indexer')
end
def indexer_bin_path
@indexer_bin_path ||= File.join(indexer_path, 'bin')
end
def indexer_version
@indexer_version ||= ::Gitlab::Elastic::Indexer.experimental_indexer_version
end
def indexer_url
ENV.fetch('GITLAB_ELASTICSEARCH_INDEXER_URL', nil)
end
private
def test_dirs
@ee_test_dirs ||= super + ['gitlab-elasticsearch-indexer']
end
end
end
......@@ -69,7 +69,7 @@ describe PostReceive do
described_class.new.perform(gl_repository, key_id, base64_changes)
end
it 'triggers wiki index update when ElasticSearch is enabled' do
it 'triggers wiki index update when ElasticSearch is enabled', :elastic do
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
expect_any_instance_of(ProjectWiki).to receive(:index_blobs)
......@@ -77,7 +77,7 @@ describe PostReceive do
described_class.new.perform(gl_repository, key_id, base64_changes)
end
context 'when limited indexing is on' do
context 'when limited indexing is on', :elastic do
before do
stub_ee_application_setting(
elasticsearch_search: true,
......
......@@ -122,7 +122,7 @@ module TestEnv
# Keeps gitlab-shell and gitlab-test
def clean_test_path
Dir[TMP_TEST_PATH].each do |entry|
unless File.basename(entry) =~ /\A(gitaly|gitlab-(shell|test|test_bare|test-fork|test-fork_bare))\z/
unless test_dirs.include?(File.basename(entry))
FileUtils.rm_rf(entry)
end
end
......@@ -312,6 +312,18 @@ module TestEnv
private
# These are directories that should be preserved at cleanup time
def test_dirs
@test_dirs ||= %w[
gitaly
gitlab-shell
gitlab-test
gitlab-test_bare
gitlab-test-fork
gitlab-test-fork_bare
]
end
def factory_repo_path
@factory_repo_path ||= Rails.root.join('tmp', 'tests', factory_repo_name)
end
......@@ -406,3 +418,8 @@ module TestEnv
true
end
end
require_relative '../../../ee/spec/support/helpers/ee/test_env'
::TestEnv.prepend(::EE::TestEnv)
::TestEnv.extend(::EE::TestEnv)
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