Commit 088ba481 authored by Rémy Coutable's avatar Rémy Coutable

Make TestEnv not depend on Rails nor a DB connection

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent f21ffd48
......@@ -149,13 +149,16 @@ setup-test-env:
- .rails-job-base
- .setup-test-env-cache
- .rails:rules:code-backstage-qa
- .use-pg12
stage: prepare
variables:
GITLAB_TEST_EAGER_LOAD: "0"
SETUP_DB: "false"
script:
- run_timed_command "bundle exec ruby -I. -e 'require \"config/environment\"; TestEnv.init'"
- run_timed_command "bundle exec ruby -I. -e 'require \"spec/support/helpers/test_env\"; TestEnv.init'"
- echo -e "\e[0Ksection_start:`date +%s`:gitaly-test-build[collapsed=true]\r\e[0KCompiling Gitaly binaries"
- run_timed_command "scripts/gitaly-test-build" # Do not use 'bundle exec' here
- echo -e "\e[0Ksection_end:`date +%s`:gitaly-test-build\r\e[0K"
artifacts:
expire_in: 7d
paths:
......
# frozen_string_literal: true
require 'omniauth'
require 'omniauth-github'
require 'etc'
require 'active_support/hash_with_indifferent_access'
require_relative '../../lib/gitlab/access'
require_relative '../settings'
require_relative '../object_store_settings'
require_relative '../smime_signature_settings'
......
......@@ -3,7 +3,7 @@
namespace :gitlab do
namespace :indexer do
desc "GitLab | Indexer | Install or upgrade gitlab-elasticsearch-indexer"
task :install, [:dir, :repo] => :gitlab_environment do |t, args|
task :install, [:dir, :repo] => :with_gitlab_helpers 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]")
......
# frozen_string_literal: true
load File.expand_path('../../../../../lib/tasks/gitlab/helpers.rake', __dir__)
load File.expand_path('../../../../lib/tasks/gitlab/indexer.rake', __dir__)
require_relative '../../../../lib/gitlab/elastic/indexer' unless defined?(Gitlab::Elastic::Indexer)
module EE
module TestEnv
def init(*args, &blk)
......@@ -9,13 +14,14 @@ module EE
end
def setup_indexer
indexer_args = [indexer_path, indexer_url].compact.join(',')
indexer_args = [indexer_path, indexer_url].compact
component_timed_setup(
'GitLab Elasticsearch Indexer',
install_dir: indexer_path,
version: indexer_version,
task: "gitlab:indexer:install[#{indexer_args}]"
task: "gitlab:indexer:install",
task_args: indexer_args
)
Settings.elasticsearch['indexer_path'] = indexer_bin_path
......
......@@ -120,7 +120,7 @@ module Gitlab
raise "storage #{storage.inspect} is missing a gitaly_address"
end
unless URI(address).scheme.in?(%w(tcp unix tls))
unless %w(tcp unix tls).include?(URI(address).scheme)
raise "Unsupported Gitaly address: #{address.inspect} does not use URL scheme 'tcp' or 'unix' or 'tls'"
end
......
# frozen_string_literal: true
require 'active_support/hash_with_indifferent_access'
module Gitlab
module GitalyClient
# This is a chokepoint that is meant to help us stop remove all places
......@@ -52,7 +54,7 @@ module Gitlab
@legacy_disk_path = File.expand_path(storage['path'], Rails.root) if storage['path']
storage['path'] = Deprecated
@hash = storage.with_indifferent_access
@hash = ActiveSupport::HashWithIndifferentAccess.new(storage)
end
def gitaly_address
......
# frozen_string_literal: true
require 'active_support/core_ext/module/delegation'
module Gitlab
module SafeRequestStore
NULL_STORE = Gitlab::NullRequestStore.new
......
# frozen_string_literal: true
require 'rainbow/ext/string'
require_dependency 'gitlab/utils/strong_memoize'
# rubocop:disable Rails/Output
......
# frozen_string_literal: true
require 'active_support/concern'
# Gitlab::VisibilityLevel module
#
# Define allowed public modes that can be used for
......
# frozen_string_literal: true
require_relative '../gitlab/task_helpers'
module SystemCheck
module Helpers
include ::Gitlab::TaskHelpers
......
......@@ -3,7 +3,7 @@
namespace :gitlab do
namespace :gitaly do
desc 'GitLab | Gitaly | Install or upgrade gitaly'
task :install, [:dir, :storage_path, :repo] => :gitlab_environment do |t, args|
task :install, [:dir, :storage_path, :repo] => :with_gitlab_helpers do |t, args|
warn_user_is_not_gitlab
unless args.dir.present? && args.storage_path.present?
......
# frozen_string_literal: true
require_relative '../../system_check/helpers'
# Prevent StateMachine warnings from outputting during a cron task
StateMachines::Machine.ignore_method_conflicts = true if ENV['CRON']
task gitlab_environment: :environment do
extend SystemCheck::Helpers
end
task :with_gitlab_helpers do
extend SystemCheck::Helpers
end
......@@ -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
......
# frozen_string_literal: true
unless defined?(Rails)
require 'request_store'
require 'rake'
require 'active_support/dependencies'
require 'active_support/core_ext/numeric'
require 'active_support/string_inquirer'
module Rails
extend self
def root
Pathname.new(File.expand_path('../../..', __dir__))
end
def env
@_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "test")
end
end
ActiveSupport::Dependencies.autoload_paths << 'lib'
load File.expand_path('../../../lib/tasks/gitlab/helpers.rake', __dir__)
load File.expand_path('../../../lib/tasks/gitlab/gitaly.rake', __dir__)
# Some files required in the requiring chain of config/initializers/1_settings needs the following.
require_relative '../../../lib/gitlab'
require_relative '../../../config/initializers/0_inject_enterprise_edition_module'
require_relative '../../../config/initializers/1_settings'
end
module TestEnv
extend ActiveSupport::Concern
extend self
ComponentFailedToInstallError = Class.new(StandardError)
......@@ -124,12 +153,6 @@ module TestEnv
setup_forked_repo
end
included do |config|
config.append_before do
set_current_example_group
end
end
def disable_mailer
allow_any_instance_of(NotificationService).to receive(:mailer)
.and_return(double.as_null_object)
......@@ -164,12 +187,13 @@ module TestEnv
end
def setup_gitaly
install_gitaly_args = [gitaly_dir, repos_path, gitaly_url].compact.join(',')
install_gitaly_args = [gitaly_dir, repos_path, gitaly_url].compact
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: install_gitaly_args) do
Gitlab::SetupHelper::Gitaly.create_configuration(
gitaly_dir,
{ 'default' => repos_path },
......@@ -468,10 +492,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 +546,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)
......@@ -539,7 +559,7 @@ module TestEnv
# 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
......
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