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
ec309a89
Commit
ec309a89
authored
May 16, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
If TestEnv#set_repo_refs fails, clean test repos and retry
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
2b778174
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
37 deletions
+36
-37
spec/factories/projects.rb
spec/factories/projects.rb
+9
-3
spec/support/test_env.rb
spec/support/test_env.rb
+27
-34
No files found.
spec/factories/projects.rb
View file @
ec309a89
...
...
@@ -92,7 +92,9 @@ FactoryGirl.define do
trait
:test_repo
do
after
:create
do
|
project
|
TestEnv
.
copy_repo
(
project
)
TestEnv
.
copy_repo
(
project
,
bare_repo:
TestEnv
.
factory_repo_path_bare
,
refs:
TestEnv
::
BRANCH_SHA
)
end
end
...
...
@@ -171,7 +173,9 @@ FactoryGirl.define do
end
after
:create
do
|
project
,
evaluator
|
TestEnv
.
copy_repo
(
project
)
TestEnv
.
copy_repo
(
project
,
bare_repo:
TestEnv
.
factory_repo_path_bare
,
refs:
TestEnv
::
BRANCH_SHA
)
if
evaluator
.
create_template
args
=
evaluator
.
create_template
...
...
@@ -204,7 +208,9 @@ FactoryGirl.define do
path
{
'forked-gitlabhq'
}
after
:create
do
|
project
|
TestEnv
.
copy_forked_repo_with_submodules
(
project
)
TestEnv
.
copy_repo
(
project
,
bare_repo:
TestEnv
.
forked_repo_path_bare
,
refs:
TestEnv
::
FORKED_BRANCH_SHA
)
end
end
...
...
spec/support/test_env.rb
View file @
ec309a89
...
...
@@ -41,8 +41,8 @@ module TestEnv
'wip'
=>
'b9238ee'
,
'csv'
=>
'3dd0896'
,
'v1.1.0'
=>
'b83d6e3'
,
'add-ipython-files'
=>
'6d85bb6
9
'
,
'add-pdf-file'
=>
'e774ebd
3
'
,
'add-ipython-files'
=>
'6d85bb6'
,
'add-pdf-file'
=>
'e774ebd'
,
'squash-large-files'
=>
'54cec52'
}.
freeze
...
...
@@ -156,14 +156,14 @@ module TestEnv
FORKED_BRANCH_SHA
)
end
def
setup_repo
(
repo_path
,
repo_path_bare
,
repo_name
,
branch_sha
)
def
setup_repo
(
repo_path
,
repo_path_bare
,
repo_name
,
refs
)
clone_url
=
"https://gitlab.com/gitlab-org/
#{
repo_name
}
.git"
unless
File
.
directory?
(
repo_path
)
system
(
*
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
clone -q
#{
clone_url
}
#{
repo_path
}
)
)
end
set_repo_refs
(
repo_path
,
branch_sha
)
set_repo_refs
(
repo_path
,
refs
)
unless
File
.
directory?
(
repo_path_bare
)
# We must copy bare repositories because we will push to them.
...
...
@@ -171,13 +171,12 @@ module TestEnv
end
end
def
copy_repo
(
project
)
base_repo_path
=
File
.
expand_path
(
factory_repo_path_bare
)
def
copy_repo
(
project
,
bare_repo
:,
refs
:)
target_repo_path
=
File
.
expand_path
(
project
.
repository_storage_path
+
"/
#{
project
.
full_path
}
.git"
)
FileUtils
.
mkdir_p
(
target_repo_path
)
FileUtils
.
cp_r
(
"
#{
base_repo_path
}
/."
,
target_repo_path
)
FileUtils
.
cp_r
(
"
#{
File
.
expand_path
(
bare_repo
)
}
/."
,
target_repo_path
)
FileUtils
.
chmod_R
0755
,
target_repo_path
set_repo_refs
(
target_repo_path
,
BRANCH_SHA
)
set_repo_refs
(
target_repo_path
,
refs
)
end
def
repos_path
...
...
@@ -192,15 +191,6 @@ module TestEnv
Gitlab
.
config
.
pages
.
path
end
def
copy_forked_repo_with_submodules
(
project
)
base_repo_path
=
File
.
expand_path
(
forked_repo_path_bare
)
target_repo_path
=
File
.
expand_path
(
project
.
repository_storage_path
+
"/
#{
project
.
full_path
}
.git"
)
FileUtils
.
mkdir_p
(
target_repo_path
)
FileUtils
.
cp_r
(
"
#{
base_repo_path
}
/."
,
target_repo_path
)
FileUtils
.
chmod_R
0755
,
target_repo_path
set_repo_refs
(
target_repo_path
,
FORKED_BRANCH_SHA
)
end
# When no cached assets exist, manually hit the root path to create them
#
# Otherwise they'd be created by the first test, often timing out and
...
...
@@ -212,16 +202,20 @@ module TestEnv
Capybara
.
current_session
.
visit
'/'
end
def
factory_repo_path_bare
"
#{
factory_repo_path
}
_bare"
end
def
forked_repo_path_bare
"
#{
forked_repo_path
}
_bare"
end
private
def
factory_repo_path
@factory_repo_path
||=
Rails
.
root
.
join
(
'tmp'
,
'tests'
,
factory_repo_name
)
end
def
factory_repo_path_bare
"
#{
factory_repo_path
}
_bare"
end
def
factory_repo_name
'gitlab-test'
end
...
...
@@ -230,10 +224,6 @@ module TestEnv
@forked_repo_path
||=
Rails
.
root
.
join
(
'tmp'
,
'tests'
,
forked_repo_name
)
end
def
forked_repo_path_bare
"
#{
forked_repo_path
}
_bare"
end
def
forked_repo_name
'gitlab-test-fork'
end
...
...
@@ -245,19 +235,22 @@ module TestEnv
end
def
set_repo_refs
(
repo_path
,
branch_sha
)
instructions
=
branch_sha
.
map
{
|
branch
,
sha
|
"update refs/heads/
#{
branch
}
\x00
#{
sha
}
\x00
"
}.
join
(
"
\x00
"
)
<<
"
\x00
"
instructions
=
branch_sha
.
map
{
|
branch
,
sha
|
"update refs/heads/
#{
branch
}
\x00
#{
sha
}
\x00
"
}.
join
(
"
\x00
"
)
<<
"
\x00
"
update_refs
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
update-ref --stdin -z)
reset
=
proc
do
IO
.
popen
(
update_refs
,
"w"
)
{
|
io
|
io
.
write
(
instructions
)
}
$?
.
success?
Dir
.
chdir
(
repo_path
)
do
IO
.
popen
(
update_refs
,
"w"
)
{
|
io
|
io
.
write
(
instructions
)
}
$?
.
success?
end
end
Dir
.
chdir
(
repo_path
)
do
# Try to reset without fetching to avoid using the network.
unless
reset
.
call
raise
'Could not fetch test seed repository.'
unless
system
(
*
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
fetch origin)
)
raise
'The fetched test seed does not contain the required revision.'
unless
reset
.
call
end
# Try to reset without fetching to avoid using the network.
unless
reset
.
call
raise
'Could not fetch test seed repository.'
unless
system
(
*
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
-C
#{
repo_path
}
fetch origin)
)
# Before we used Git clone's --mirror option, bare repos could end up
# with missing refs, clearing them and retrying should fix the issue.
cleanup
&&
init
unless
reset
.
call
end
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