Commit 817aa53e authored by Rémy Coutable's avatar Rémy Coutable

Run setup test env tasks in parallel

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 088ba481
...@@ -4,27 +4,32 @@ load File.expand_path('../../../../../lib/tasks/gitlab/helpers.rake', __dir__) ...@@ -4,27 +4,32 @@ load File.expand_path('../../../../../lib/tasks/gitlab/helpers.rake', __dir__)
load File.expand_path('../../../../lib/tasks/gitlab/indexer.rake', __dir__) load File.expand_path('../../../../lib/tasks/gitlab/indexer.rake', __dir__)
require_relative '../../../../lib/gitlab/elastic/indexer' unless defined?(Gitlab::Elastic::Indexer) require_relative '../../../../lib/gitlab/elastic/indexer' unless defined?(Gitlab::Elastic::Indexer)
require_relative '../../../../../lib/gitlab/utils/override'
module EE module EE
module TestEnv module TestEnv
def init(*args, &blk) extend ::Gitlab::Utils::Override
override :setup_methods
def setup_methods
(super + [:setup_indexer]).freeze
end
override :post_init
def post_init
super super
setup_indexer Settings.elasticsearch['indexer_path'] = indexer_bin_path
end end
def setup_indexer def setup_indexer
indexer_args = [indexer_path, indexer_url].compact
component_timed_setup( component_timed_setup(
'GitLab Elasticsearch Indexer', 'GitLab Elasticsearch Indexer',
install_dir: indexer_path, install_dir: indexer_path,
version: indexer_version, version: indexer_version,
task: "gitlab:indexer:install", task: "gitlab:indexer:install",
task_args: indexer_args task_args: [indexer_path, indexer_url].compact
) )
Settings.elasticsearch['indexer_path'] = indexer_bin_path
end end
def indexer_path def indexer_path
......
# frozen_string_literal: true # frozen_string_literal: true
require 'parallel'
unless defined?(Rails) unless defined?(Rails)
require 'request_store' require 'request_store'
require 'rake' require 'rake'
...@@ -123,44 +125,40 @@ module TestEnv ...@@ -123,44 +125,40 @@ module TestEnv
TMP_TEST_PATH = Rails.root.join('tmp', 'tests').freeze TMP_TEST_PATH = Rails.root.join('tmp', 'tests').freeze
REPOS_STORAGE = 'default' REPOS_STORAGE = 'default'
SECOND_STORAGE_PATH = Rails.root.join('tmp', 'tests', 'second_storage') SECOND_STORAGE_PATH = Rails.root.join('tmp', 'tests', 'second_storage')
SETUP_METHODS = %i[setup_gitaly setup_gitlab_shell setup_workhorse setup_factory_repo setup_forked_repo].freeze
# Can be overriden
def setup_methods
SETUP_METHODS
end
# Test environment # Test environment
# #
# See gitlab.yml.example test section for paths # See gitlab.yml.example test section for paths
# #
def init(opts = {}) def init
unless Rails.env.test? unless Rails.env.test?
puts "\nTestEnv.init can only be run if `RAILS_ENV` is set to 'test' not '#{Rails.env}'!\n" puts "\nTestEnv.init can only be run if `RAILS_ENV` is set to 'test' not '#{Rails.env}'!\n"
exit 1 exit 1
end end
start = Time.now
# Disable mailer for spinach tests # Disable mailer for spinach tests
disable_mailer if opts[:mailer] == false
clean_test_path clean_test_path
setup_gitlab_shell # Install components in parallel as most of the setup is I/O.
Parallel.each(setup_methods) do |method|
setup_gitaly public_send(method)
end
# Feature specs are run through Workhorse
setup_workhorse
# Create repository for FactoryBot.create(:project)
setup_factory_repo
# Create repository for FactoryBot.create(:forked_project_with_submodules) post_init
setup_forked_repo
end
def disable_mailer puts "\nTest environment set up in #{Time.now - start} seconds"
allow_any_instance_of(NotificationService).to receive(:mailer)
.and_return(double.as_null_object)
end end
def enable_mailer # Can be overriden
allow_any_instance_of(NotificationService).to receive(:mailer) def post_init
.and_call_original start_gitaly(gitaly_dir)
end end
# Clean /tmp/tests # Clean /tmp/tests
...@@ -187,13 +185,11 @@ module TestEnv ...@@ -187,13 +185,11 @@ module TestEnv
end end
def setup_gitaly def setup_gitaly
install_gitaly_args = [gitaly_dir, repos_path, gitaly_url].compact
component_timed_setup('Gitaly', component_timed_setup('Gitaly',
install_dir: gitaly_dir, install_dir: gitaly_dir,
version: Gitlab::GitalyClient.expected_server_version, version: Gitlab::GitalyClient.expected_server_version,
task: "gitlab:gitaly:install", task: "gitlab:gitaly:install",
task_args: install_gitaly_args) do task_args: [gitaly_dir, repos_path, gitaly_url].compact) do
Gitlab::SetupHelper::Gitaly.create_configuration( Gitlab::SetupHelper::Gitaly.create_configuration(
gitaly_dir, gitaly_dir,
{ 'default' => repos_path }, { 'default' => repos_path },
...@@ -214,8 +210,6 @@ module TestEnv ...@@ -214,8 +210,6 @@ module TestEnv
) )
Gitlab::SetupHelper::Praefect.create_configuration(gitaly_dir, { 'praefect' => repos_path }, force: true) Gitlab::SetupHelper::Praefect.create_configuration(gitaly_dir, { 'praefect' => repos_path }, force: true)
end end
start_gitaly(gitaly_dir)
end end
def gitaly_socket_path def gitaly_socket_path
...@@ -297,19 +291,18 @@ module TestEnv ...@@ -297,19 +291,18 @@ module TestEnv
raise "could not connect to #{service} at #{socket.inspect} after #{sleep_time} seconds" raise "could not connect to #{service} at #{socket.inspect} after #{sleep_time} seconds"
end end
# Feature specs are run through Workhorse
def setup_workhorse def setup_workhorse
start = Time.now start = Time.now
return if skip_compile_workhorse? return if skip_compile_workhorse?
puts "\n==> Setting up GitLab Workhorse..."
FileUtils.rm_rf(workhorse_dir) FileUtils.rm_rf(workhorse_dir)
Gitlab::SetupHelper::Workhorse.compile_into(workhorse_dir) Gitlab::SetupHelper::Workhorse.compile_into(workhorse_dir)
Gitlab::SetupHelper::Workhorse.create_configuration(workhorse_dir, nil) Gitlab::SetupHelper::Workhorse.create_configuration(workhorse_dir, nil)
File.write(workhorse_tree_file, workhorse_tree) if workhorse_source_clean? File.write(workhorse_tree_file, workhorse_tree) if workhorse_source_clean?
puts " GitLab Workhorse set up in #{Time.now - start} seconds...\n" puts "==> GitLab Workhorse set up in #{Time.now - start} seconds...\n"
end end
def skip_compile_workhorse? def skip_compile_workhorse?
...@@ -373,10 +366,12 @@ module TestEnv ...@@ -373,10 +366,12 @@ module TestEnv
ENV.fetch('GITLAB_WORKHORSE_URL', nil) ENV.fetch('GITLAB_WORKHORSE_URL', nil)
end end
# Create repository for FactoryBot.create(:project)
def setup_factory_repo def setup_factory_repo
setup_repo(factory_repo_path, factory_repo_path_bare, factory_repo_name, BRANCH_SHA) setup_repo(factory_repo_path, factory_repo_path_bare, factory_repo_name, BRANCH_SHA)
end end
# Create repository for FactoryBot.create(:forked_project_with_submodules)
# This repo has a submodule commit that is not present in the main test # This repo has a submodule commit that is not present in the main test
# repository. # repository.
def setup_forked_repo def setup_forked_repo
...@@ -387,20 +382,18 @@ module TestEnv ...@@ -387,20 +382,18 @@ module TestEnv
clone_url = "https://gitlab.com/gitlab-org/#{repo_name}.git" clone_url = "https://gitlab.com/gitlab-org/#{repo_name}.git"
unless File.directory?(repo_path) unless File.directory?(repo_path)
puts "\n==> Setting up #{repo_name} repository in #{repo_path}..."
start = Time.now start = Time.now
system(*%W(#{Gitlab.config.git.bin_path} clone --quiet -- #{clone_url} #{repo_path})) system(*%W(#{Gitlab.config.git.bin_path} clone --quiet -- #{clone_url} #{repo_path}))
puts " #{repo_path} set up in #{Time.now - start} seconds...\n" puts "==> #{repo_path} set up in #{Time.now - start} seconds...\n"
end end
set_repo_refs(repo_path, refs) set_repo_refs(repo_path, refs)
unless File.directory?(repo_path_bare) unless File.directory?(repo_path_bare)
puts "\n==> Setting up #{repo_name} bare repository in #{repo_path_bare}..."
start = Time.now start = Time.now
# We must copy bare repositories because we will push to them. # We must copy bare repositories because we will push to them.
system(git_env, *%W(#{Gitlab.config.git.bin_path} clone --quiet --bare -- #{repo_path} #{repo_path_bare})) system(git_env, *%W(#{Gitlab.config.git.bin_path} clone --quiet --bare -- #{repo_path} #{repo_path_bare}))
puts " #{repo_path_bare} set up in #{Time.now - start} seconds...\n" puts "==> #{repo_path_bare} set up in #{Time.now - start} seconds...\n"
end end
end end
...@@ -555,7 +548,6 @@ module TestEnv ...@@ -555,7 +548,6 @@ module TestEnv
return if File.exist?(install_dir) && ci? return if File.exist?(install_dir) && ci?
if component_needs_update?(install_dir, version) if component_needs_update?(install_dir, version)
puts "\n==> Setting up #{component}..."
# Cleanup the component entirely to ensure we start fresh # Cleanup the component entirely to ensure we start fresh
FileUtils.rm_rf(install_dir) FileUtils.rm_rf(install_dir)
...@@ -565,7 +557,7 @@ module TestEnv ...@@ -565,7 +557,7 @@ module TestEnv
yield if block_given? yield if block_given?
puts " #{component} set up in #{Time.now - start} seconds...\n" puts "==> #{component} set up in #{Time.now - start} seconds...\n"
end end
rescue ComponentFailedToInstallError rescue ComponentFailedToInstallError
puts "\n#{component} failed to install, cleaning up #{install_dir}!\n" puts "\n#{component} failed to install, cleaning up #{install_dir}!\n"
......
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