BigW Consortium Gitlab

Commit c9c4d537 by Robert Speicher

Merge branch '31562-fix-test_env-set_repo_refs-rspec-profile' into 'master'

Resolve "TestEnv#set_repo_refs fails to update refs sometimes" Closes #31562 See merge request !11253
parents 2e73d447 ba441bb6
...@@ -60,7 +60,9 @@ FactoryGirl.define do ...@@ -60,7 +60,9 @@ FactoryGirl.define do
trait :test_repo do trait :test_repo do
after :create do |project| 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
end end
...@@ -139,7 +141,9 @@ FactoryGirl.define do ...@@ -139,7 +141,9 @@ FactoryGirl.define do
end end
after :create do |project, evaluator| 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 if evaluator.create_template
args = evaluator.create_template args = evaluator.create_template
...@@ -172,7 +176,9 @@ FactoryGirl.define do ...@@ -172,7 +176,9 @@ FactoryGirl.define do
path { 'forked-gitlabhq' } path { 'forked-gitlabhq' }
after :create do |project| 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
end end
......
...@@ -40,8 +40,8 @@ module TestEnv ...@@ -40,8 +40,8 @@ module TestEnv
'wip' => 'b9238ee', 'wip' => 'b9238ee',
'csv' => '3dd0896', 'csv' => '3dd0896',
'v1.1.0' => 'b83d6e3', 'v1.1.0' => 'b83d6e3',
'add-ipython-files' => '6d85bb69', 'add-ipython-files' => '6d85bb6',
'add-pdf-file' => 'e774ebd3' 'add-pdf-file' => 'e774ebd'
}.freeze }.freeze
# gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily # gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily
...@@ -155,14 +155,14 @@ module TestEnv ...@@ -155,14 +155,14 @@ module TestEnv
FORKED_BRANCH_SHA) FORKED_BRANCH_SHA)
end 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" clone_url = "https://gitlab.com/gitlab-org/#{repo_name}.git"
unless File.directory?(repo_path) unless File.directory?(repo_path)
system(*%W(#{Gitlab.config.git.bin_path} clone -q #{clone_url} #{repo_path})) system(*%W(#{Gitlab.config.git.bin_path} clone -q #{clone_url} #{repo_path}))
end end
set_repo_refs(repo_path, branch_sha) set_repo_refs(repo_path, refs)
unless File.directory?(repo_path_bare) unless File.directory?(repo_path_bare)
# We must copy bare repositories because we will push to them. # We must copy bare repositories because we will push to them.
...@@ -170,13 +170,12 @@ module TestEnv ...@@ -170,13 +170,12 @@ module TestEnv
end end
end end
def copy_repo(project) def copy_repo(project, bare_repo:, refs:)
base_repo_path = File.expand_path(factory_repo_path_bare)
target_repo_path = File.expand_path(project.repository_storage_path + "/#{project.full_path}.git") target_repo_path = File.expand_path(project.repository_storage_path + "/#{project.full_path}.git")
FileUtils.mkdir_p(target_repo_path) 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 FileUtils.chmod_R 0755, target_repo_path
set_repo_refs(target_repo_path, BRANCH_SHA) set_repo_refs(target_repo_path, refs)
end end
def repos_path def repos_path
...@@ -191,15 +190,6 @@ module TestEnv ...@@ -191,15 +190,6 @@ module TestEnv
Gitlab.config.pages.path Gitlab.config.pages.path
end 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 # 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 # Otherwise they'd be created by the first test, often timing out and
...@@ -211,16 +201,20 @@ module TestEnv ...@@ -211,16 +201,20 @@ module TestEnv
Capybara.current_session.visit '/' Capybara.current_session.visit '/'
end end
def factory_repo_path_bare
"#{factory_repo_path}_bare"
end
def forked_repo_path_bare
"#{forked_repo_path}_bare"
end
private private
def factory_repo_path def factory_repo_path
@factory_repo_path ||= Rails.root.join('tmp', 'tests', factory_repo_name) @factory_repo_path ||= Rails.root.join('tmp', 'tests', factory_repo_name)
end end
def factory_repo_path_bare
"#{factory_repo_path}_bare"
end
def factory_repo_name def factory_repo_name
'gitlab-test' 'gitlab-test'
end end
...@@ -229,10 +223,6 @@ module TestEnv ...@@ -229,10 +223,6 @@ module TestEnv
@forked_repo_path ||= Rails.root.join('tmp', 'tests', forked_repo_name) @forked_repo_path ||= Rails.root.join('tmp', 'tests', forked_repo_name)
end end
def forked_repo_path_bare
"#{forked_repo_path}_bare"
end
def forked_repo_name def forked_repo_name
'gitlab-test-fork' 'gitlab-test-fork'
end end
...@@ -244,19 +234,22 @@ module TestEnv ...@@ -244,19 +234,22 @@ module TestEnv
end end
def set_repo_refs(repo_path, branch_sha) 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) update_refs = %W(#{Gitlab.config.git.bin_path} update-ref --stdin -z)
reset = proc do reset = proc do
IO.popen(update_refs, "w") {|io| io.write(instructions) } Dir.chdir(repo_path) do
$?.success? IO.popen(update_refs, "w") { |io| io.write(instructions) }
$?.success?
end
end end
Dir.chdir(repo_path) do # Try to reset without fetching to avoid using the network.
# Try to reset without fetching to avoid using the network. unless reset.call
unless reset.call raise 'Could not fetch test seed repository.' unless system(*%W(#{Gitlab.config.git.bin_path} -C #{repo_path} fetch origin))
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 # Before we used Git clone's --mirror option, bare repos could end up
end # with missing refs, clearing them and retrying should fix the issue.
cleanup && init unless reset.call
end end
end end
end 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