Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-06-05 21:10:05 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-05 21:10:05 +0300
commit585c8dce43fd374a18e48e03c7ba8b5b96395b14 (patch)
treebc91d7a2ea940133a7a6ac323e0be9eb6f513282 /spec
parent35cccb0c12024672d5a6e003fb0fb920fc9a323f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/spec_helper.rb4
-rw-r--r--spec/support/helpers/test_env.rb78
2 files changed, 34 insertions, 48 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index bd9ba53c04c..1c852b85ff5 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -230,6 +230,10 @@ RSpec.configure do |config|
Gitlab::Database.set_open_transactions_baseline
end
+ config.append_before do
+ Thread.current[:current_example_group] = ::RSpec.current_example.metadata[:example_group]
+ end
+
config.append_after do
Gitlab::Database.reset_open_transactions_baseline
end
diff --git a/spec/support/helpers/test_env.rb b/spec/support/helpers/test_env.rb
index 40a3dbfbf25..29aefbeb99c 100644
--- a/spec/support/helpers/test_env.rb
+++ b/spec/support/helpers/test_env.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
+require 'parallel'
+
module TestEnv
- extend ActiveSupport::Concern
extend self
ComponentFailedToInstallError = Class.new(StandardError)
@@ -94,50 +95,40 @@ module TestEnv
TMP_TEST_PATH = Rails.root.join('tmp', 'tests').freeze
REPOS_STORAGE = 'default'
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
#
# See gitlab.yml.example test section for paths
#
- def init(opts = {})
+ def init
unless Rails.env.test?
puts "\nTestEnv.init can only be run if `RAILS_ENV` is set to 'test' not '#{Rails.env}'!\n"
exit 1
end
+ start = Time.now
# Disable mailer for spinach tests
- disable_mailer if opts[:mailer] == false
-
clean_test_path
- setup_gitlab_shell
-
- setup_gitaly
-
- # 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)
- setup_forked_repo
- end
-
- included do |config|
- config.append_before do
- set_current_example_group
+ # Install components in parallel as most of the setup is I/O.
+ Parallel.each(setup_methods) do |method|
+ public_send(method)
end
- end
- def disable_mailer
- allow_any_instance_of(NotificationService).to receive(:mailer)
- .and_return(double.as_null_object)
+ post_init
+
+ puts "\nTest environment set up in #{Time.now - start} seconds"
end
- def enable_mailer
- allow_any_instance_of(NotificationService).to receive(:mailer)
- .and_call_original
+ # Can be overriden
+ def post_init
+ start_gitaly(gitaly_dir)
end
# Clean /tmp/tests
@@ -164,12 +155,11 @@ module TestEnv
end
def setup_gitaly
- install_gitaly_args = [gitaly_dir, repos_path, gitaly_url].compact.join(',')
-
component_timed_setup('Gitaly',
install_dir: gitaly_dir,
version: Gitlab::GitalyClient.expected_server_version,
- task: "gitlab:gitaly:install[#{install_gitaly_args}]") do
+ task: "gitlab:gitaly:install",
+ task_args: [gitaly_dir, repos_path, gitaly_url].compact) do
Gitlab::SetupHelper::Gitaly.create_configuration(
gitaly_dir,
{ 'default' => repos_path },
@@ -190,8 +180,6 @@ module TestEnv
)
Gitlab::SetupHelper::Praefect.create_configuration(gitaly_dir, { 'praefect' => repos_path }, force: true)
end
-
- start_gitaly(gitaly_dir)
end
def gitaly_socket_path
@@ -273,19 +261,18 @@ module TestEnv
raise "could not connect to #{service} at #{socket.inspect} after #{sleep_time} seconds"
end
+ # Feature specs are run through Workhorse
def setup_workhorse
start = Time.now
return if skip_compile_workhorse?
- puts "\n==> Setting up GitLab Workhorse..."
-
FileUtils.rm_rf(workhorse_dir)
Gitlab::SetupHelper::Workhorse.compile_into(workhorse_dir)
Gitlab::SetupHelper::Workhorse.create_configuration(workhorse_dir, nil)
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
def skip_compile_workhorse?
@@ -349,10 +336,12 @@ module TestEnv
ENV.fetch('GITLAB_WORKHORSE_URL', nil)
end
+ # Create repository for FactoryBot.create(:project)
def setup_factory_repo
setup_repo(factory_repo_path, factory_repo_path_bare, factory_repo_name, BRANCH_SHA)
end
+ # Create repository for FactoryBot.create(:forked_project_with_submodules)
# This repo has a submodule commit that is not present in the main test
# repository.
def setup_forked_repo
@@ -363,20 +352,18 @@ module TestEnv
clone_url = "https://gitlab.com/gitlab-org/#{repo_name}.git"
unless File.directory?(repo_path)
- puts "\n==> Setting up #{repo_name} repository in #{repo_path}..."
start = Time.now
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
set_repo_refs(repo_path, refs)
unless File.directory?(repo_path_bare)
- puts "\n==> Setting up #{repo_name} bare repository in #{repo_path_bare}..."
start = Time.now
# 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}))
- 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
@@ -468,10 +455,6 @@ module TestEnv
private
- def set_current_example_group
- Thread.current[:current_example_group] = ::RSpec.current_example.metadata[:example_group]
- end
-
# These are directories that should be preserved at cleanup time
def test_dirs
@test_dirs ||= %w[
@@ -526,7 +509,7 @@ module TestEnv
end
end
- def component_timed_setup(component, install_dir:, version:, task:)
+ def component_timed_setup(component, install_dir:, version:, task:, task_args: [])
start = Time.now
ensure_component_dir_name_is_correct!(component, install_dir)
@@ -535,17 +518,16 @@ module TestEnv
return if File.exist?(install_dir) && ci?
if component_needs_update?(install_dir, version)
- puts "\n==> Setting up #{component}..."
# Cleanup the component entirely to ensure we start fresh
FileUtils.rm_rf(install_dir)
- unless system('rake', task)
+ unless Rake::Task[task].invoke(*task_args)
raise ComponentFailedToInstallError
end
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
rescue ComponentFailedToInstallError
puts "\n#{component} failed to install, cleaning up #{install_dir}!\n"