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
f16a4b22
Commit
f16a4b22
authored
Oct 30, 2020
by
Robert May
Committed by
Sean McGivern
Oct 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass environment to check threads
This ensures the git environment is passed to the parallel check threads.
parent
fa312dfb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
6 deletions
+33
-6
ee/lib/ee/gitlab/checks/push_rule_check.rb
ee/lib/ee/gitlab/checks/push_rule_check.rb
+15
-5
ee/spec/lib/ee/gitlab/checks/push_rule_check_spec.rb
ee/spec/lib/ee/gitlab/checks/push_rule_check_spec.rb
+18
-1
No files found.
ee/lib/ee/gitlab/checks/push_rule_check.rb
View file @
f16a4b22
...
...
@@ -41,18 +41,23 @@ module EE
check_file_size!
end
# Run the checks in separate threads for performance benefits
# Run the checks in separate threads for performance benefits.
#
# The git hook environment is currently set in the current thread
# in lib/api/internal/base.rb. This needs to be passed into the
# child threads we spawn here.
#
# @return [Nil] returns nil unless an error is raised
# @raise [Gitlab::GitAccess::ForbiddenError] if any check fails
def
run_checks_in_parallel!
git_env
=
::
Gitlab
::
Git
::
HookEnv
.
all
(
project
.
repository
.
gl_repository
)
@threads
=
[]
parallelize
do
parallelize
(
git_env
)
do
check_tag_or_branch!
end
parallelize
do
parallelize
(
git_env
)
do
check_file_size!
end
...
...
@@ -73,8 +78,9 @@ module EE
# Runs a block inside a new thread. This thread will
# exit immediately upon an exception being raised.
#
# @param git_env [Hash] the current git environment
# @raise [Gitlab::GitAccess::ForbiddenError]
def
parallelize
def
parallelize
(
git_env
)
@threads
<<
Thread
.
new
do
Thread
.
current
.
tap
do
|
t
|
t
.
name
=
"push_rule_check"
...
...
@@ -82,7 +88,11 @@ module EE
t
.
report_on_exception
=
false
end
::
Gitlab
::
WithRequestStore
.
with_request_store
do
::
Gitlab
::
Git
::
HookEnv
.
set
(
project
.
repository
.
gl_repository
,
git_env
)
yield
end
ensure
# rubocop: disable Layout/RescueEnsureAlignment
ActiveRecord
::
Base
.
clear_active_connections!
end
...
...
ee/spec/lib/ee/gitlab/checks/push_rule_check_spec.rb
View file @
f16a4b22
...
...
@@ -59,8 +59,25 @@ RSpec.describe EE::Gitlab::Checks::PushRuleCheck do
end
describe
'#validate!'
do
context
"parallel push checks"
do
it_behaves_like
"push checks"
before
do
::
Gitlab
::
Git
::
HookEnv
.
set
(
project
.
repository
.
gl_repository
,
"GIT_OBJECT_DIRECTORY_RELATIVE"
=>
"objects"
,
"GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE"
=>
[])
end
it
"sets the git env correctly for all hooks"
,
:request_store
do
expect
(
Gitaly
::
Repository
).
to
receive
(
:new
)
.
with
(
a_hash_including
(
git_object_directory:
"objects"
))
.
and_call_original
# This push fails because of the commit message check
expect
{
subject
.
validate!
}.
to
raise_error
(
Gitlab
::
GitAccess
::
ForbiddenError
)
end
end
context
":parallel_push_checks feature is disabled"
do
before
do
stub_feature_flags
(
parallel_push_checks:
false
)
...
...
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