Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
088ba481
Commit
088ba481
authored
May 06, 2021
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make TestEnv not depend on Rails nor a DB connection
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
f21ffd48
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
77 additions
and
23 deletions
+77
-23
.gitlab/ci/rails.gitlab-ci.yml
.gitlab/ci/rails.gitlab-ci.yml
+5
-2
config/initializers/1_settings.rb
config/initializers/1_settings.rb
+6
-0
ee/lib/tasks/gitlab/indexer.rake
ee/lib/tasks/gitlab/indexer.rake
+1
-1
ee/spec/support/helpers/ee/test_env.rb
ee/spec/support/helpers/ee/test_env.rb
+8
-2
lib/gitlab/gitaly_client.rb
lib/gitlab/gitaly_client.rb
+1
-1
lib/gitlab/gitaly_client/storage_settings.rb
lib/gitlab/gitaly_client/storage_settings.rb
+3
-1
lib/gitlab/safe_request_store.rb
lib/gitlab/safe_request_store.rb
+2
-0
lib/gitlab/task_helpers.rb
lib/gitlab/task_helpers.rb
+1
-0
lib/gitlab/visibility_level.rb
lib/gitlab/visibility_level.rb
+2
-0
lib/system_check/helpers.rb
lib/system_check/helpers.rb
+2
-0
lib/tasks/gitlab/gitaly.rake
lib/tasks/gitlab/gitaly.rake
+1
-1
lib/tasks/gitlab/helpers.rake
lib/tasks/gitlab/helpers.rake
+6
-0
spec/spec_helper.rb
spec/spec_helper.rb
+4
-0
spec/support/helpers/test_env.rb
spec/support/helpers/test_env.rb
+35
-15
No files found.
.gitlab/ci/rails.gitlab-ci.yml
View file @
088ba481
...
@@ -149,13 +149,16 @@ setup-test-env:
...
@@ -149,13 +149,16 @@ setup-test-env:
-
.rails-job-base
-
.rails-job-base
-
.setup-test-env-cache
-
.setup-test-env-cache
-
.rails:rules:code-backstage-qa
-
.rails:rules:code-backstage-qa
-
.use-pg12
stage
:
prepare
stage
:
prepare
variables
:
variables
:
GITLAB_TEST_EAGER_LOAD
:
"
0"
GITLAB_TEST_EAGER_LOAD
:
"
0"
SETUP_DB
:
"
false"
script
:
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
-
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
:
artifacts
:
expire_in
:
7d
expire_in
:
7d
paths
:
paths
:
...
...
config/initializers/1_settings.rb
View file @
088ba481
# frozen_string_literal: true
# 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
'../settings'
require_relative
'../object_store_settings'
require_relative
'../object_store_settings'
require_relative
'../smime_signature_settings'
require_relative
'../smime_signature_settings'
...
...
ee/lib/tasks/gitlab/indexer.rake
View file @
088ba481
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
namespace
:gitlab
do
namespace
:gitlab
do
namespace
:indexer
do
namespace
:indexer
do
desc
"GitLab | Indexer | Install or upgrade gitlab-elasticsearch-indexer"
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?
unless
args
.
dir
.
present?
abort
%(Please specify the directory where you want to install the indexer
abort
%(Please specify the directory where you want to install the indexer
Usage: rake "gitlab:indexer:install[/installation/dir,repo]")
Usage: rake "gitlab:indexer:install[/installation/dir,repo]")
...
...
ee/spec/support/helpers/ee/test_env.rb
View file @
088ba481
# frozen_string_literal: true
# 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
EE
module
TestEnv
module
TestEnv
def
init
(
*
args
,
&
blk
)
def
init
(
*
args
,
&
blk
)
...
@@ -9,13 +14,14 @@ module EE
...
@@ -9,13 +14,14 @@ module EE
end
end
def
setup_indexer
def
setup_indexer
indexer_args
=
[
indexer_path
,
indexer_url
].
compact
.
join
(
','
)
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[
#{
indexer_args
}
]"
task:
"gitlab:indexer:install"
,
task_args:
indexer_args
)
)
Settings
.
elasticsearch
[
'indexer_path'
]
=
indexer_bin_path
Settings
.
elasticsearch
[
'indexer_path'
]
=
indexer_bin_path
...
...
lib/gitlab/gitaly_client.rb
View file @
088ba481
...
@@ -120,7 +120,7 @@ module Gitlab
...
@@ -120,7 +120,7 @@ module Gitlab
raise
"storage
#{
storage
.
inspect
}
is missing a gitaly_address"
raise
"storage
#{
storage
.
inspect
}
is missing a gitaly_address"
end
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'"
raise
"Unsupported Gitaly address:
#{
address
.
inspect
}
does not use URL scheme 'tcp' or 'unix' or 'tls'"
end
end
...
...
lib/gitlab/gitaly_client/storage_settings.rb
View file @
088ba481
# frozen_string_literal: true
# frozen_string_literal: true
require
'active_support/hash_with_indifferent_access'
module
Gitlab
module
Gitlab
module
GitalyClient
module
GitalyClient
# This is a chokepoint that is meant to help us stop remove all places
# This is a chokepoint that is meant to help us stop remove all places
...
@@ -52,7 +54,7 @@ module Gitlab
...
@@ -52,7 +54,7 @@ module Gitlab
@legacy_disk_path
=
File
.
expand_path
(
storage
[
'path'
],
Rails
.
root
)
if
storage
[
'path'
]
@legacy_disk_path
=
File
.
expand_path
(
storage
[
'path'
],
Rails
.
root
)
if
storage
[
'path'
]
storage
[
'path'
]
=
Deprecated
storage
[
'path'
]
=
Deprecated
@hash
=
storage
.
with_indifferent_access
@hash
=
ActiveSupport
::
HashWithIndifferentAccess
.
new
(
storage
)
end
end
def
gitaly_address
def
gitaly_address
...
...
lib/gitlab/safe_request_store.rb
View file @
088ba481
# frozen_string_literal: true
# frozen_string_literal: true
require
'active_support/core_ext/module/delegation'
module
Gitlab
module
Gitlab
module
SafeRequestStore
module
SafeRequestStore
NULL_STORE
=
Gitlab
::
NullRequestStore
.
new
NULL_STORE
=
Gitlab
::
NullRequestStore
.
new
...
...
lib/gitlab/task_helpers.rb
View file @
088ba481
# frozen_string_literal: true
# frozen_string_literal: true
require
'rainbow/ext/string'
require
'rainbow/ext/string'
require_dependency
'gitlab/utils/strong_memoize'
require_dependency
'gitlab/utils/strong_memoize'
# rubocop:disable Rails/Output
# rubocop:disable Rails/Output
...
...
lib/gitlab/visibility_level.rb
View file @
088ba481
# frozen_string_literal: true
# frozen_string_literal: true
require
'active_support/concern'
# Gitlab::VisibilityLevel module
# Gitlab::VisibilityLevel module
#
#
# Define allowed public modes that can be used for
# Define allowed public modes that can be used for
...
...
lib/system_check/helpers.rb
View file @
088ba481
# frozen_string_literal: true
# frozen_string_literal: true
require_relative
'../gitlab/task_helpers'
module
SystemCheck
module
SystemCheck
module
Helpers
module
Helpers
include
::
Gitlab
::
TaskHelpers
include
::
Gitlab
::
TaskHelpers
...
...
lib/tasks/gitlab/gitaly.rake
View file @
088ba481
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
namespace
:gitlab
do
namespace
:gitlab
do
namespace
:gitaly
do
namespace
:gitaly
do
desc
'GitLab | Gitaly | Install or upgrade gitaly'
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
warn_user_is_not_gitlab
unless
args
.
dir
.
present?
&&
args
.
storage_path
.
present?
unless
args
.
dir
.
present?
&&
args
.
storage_path
.
present?
...
...
lib/tasks/gitlab/helpers.rake
View file @
088ba481
# frozen_string_literal: true
# frozen_string_literal: true
require_relative
'../../system_check/helpers'
# Prevent StateMachine warnings from outputting during a cron task
# Prevent StateMachine warnings from outputting during a cron task
StateMachines
::
Machine
.
ignore_method_conflicts
=
true
if
ENV
[
'CRON'
]
StateMachines
::
Machine
.
ignore_method_conflicts
=
true
if
ENV
[
'CRON'
]
task
gitlab_environment: :environment
do
task
gitlab_environment: :environment
do
extend
SystemCheck
::
Helpers
extend
SystemCheck
::
Helpers
end
end
task
:with_gitlab_helpers
do
extend
SystemCheck
::
Helpers
end
spec/spec_helper.rb
View file @
088ba481
...
@@ -230,6 +230,10 @@ RSpec.configure do |config|
...
@@ -230,6 +230,10 @@ RSpec.configure do |config|
Gitlab
::
Database
.
set_open_transactions_baseline
Gitlab
::
Database
.
set_open_transactions_baseline
end
end
config
.
append_before
do
Thread
.
current
[
:current_example_group
]
=
::
RSpec
.
current_example
.
metadata
[
:example_group
]
end
config
.
append_after
do
config
.
append_after
do
Gitlab
::
Database
.
reset_open_transactions_baseline
Gitlab
::
Database
.
reset_open_transactions_baseline
end
end
...
...
spec/support/helpers/test_env.rb
View file @
088ba481
# frozen_string_literal: true
# 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
module
TestEnv
extend
ActiveSupport
::
Concern
extend
self
extend
self
ComponentFailedToInstallError
=
Class
.
new
(
StandardError
)
ComponentFailedToInstallError
=
Class
.
new
(
StandardError
)
...
@@ -124,12 +153,6 @@ module TestEnv
...
@@ -124,12 +153,6 @@ module TestEnv
setup_forked_repo
setup_forked_repo
end
end
included
do
|
config
|
config
.
append_before
do
set_current_example_group
end
end
def
disable_mailer
def
disable_mailer
allow_any_instance_of
(
NotificationService
).
to
receive
(
:mailer
)
allow_any_instance_of
(
NotificationService
).
to
receive
(
:mailer
)
.
and_return
(
double
.
as_null_object
)
.
and_return
(
double
.
as_null_object
)
...
@@ -164,12 +187,13 @@ module TestEnv
...
@@ -164,12 +187,13 @@ module TestEnv
end
end
def
setup_gitaly
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'
,
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[
#{
install_gitaly_args
}
]"
)
do
task:
"gitlab:gitaly:install"
,
task_args:
install_gitaly_args
)
do
Gitlab
::
SetupHelper
::
Gitaly
.
create_configuration
(
Gitlab
::
SetupHelper
::
Gitaly
.
create_configuration
(
gitaly_dir
,
gitaly_dir
,
{
'default'
=>
repos_path
},
{
'default'
=>
repos_path
},
...
@@ -468,10 +492,6 @@ module TestEnv
...
@@ -468,10 +492,6 @@ module TestEnv
private
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
# These are directories that should be preserved at cleanup time
def
test_dirs
def
test_dirs
@test_dirs
||=
%w[
@test_dirs
||=
%w[
...
@@ -526,7 +546,7 @@ module TestEnv
...
@@ -526,7 +546,7 @@ module TestEnv
end
end
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
start
=
Time
.
now
ensure_component_dir_name_is_correct!
(
component
,
install_dir
)
ensure_component_dir_name_is_correct!
(
component
,
install_dir
)
...
@@ -539,7 +559,7 @@ module TestEnv
...
@@ -539,7 +559,7 @@ module TestEnv
# 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
)
unless
system
(
'rake'
,
task
)
unless
Rake
::
Task
[
task
].
invoke
(
*
task_args
)
raise
ComponentFailedToInstallError
raise
ComponentFailedToInstallError
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment