Commit 4bc96d3a authored by Jacob Vosmaer's avatar Jacob Vosmaer

Speed up Rspec workhorse setup

Instead of invoking 'rake gitlab:workhorse:install' during Rspec boot,
go straight to 'make -C workhorse install'.
parent 47b1a8d0
......@@ -44,6 +44,24 @@ module Gitlab
def get_config_path(dir)
File.join(dir, 'config.toml')
end
def compile_into(dir)
command = %W[#{make} -C #{Rails.root.join('workhorse')} install PREFIX=#{File.absolute_path(dir)}]
make_out, make_status = Gitlab::Popen.popen(command)
unless make_status == 0
warn make_out
raise 'workhorse make failed'
end
# 'make install' puts the binaries in #{dir}/bin but the init script expects them in dir
FileUtils.mv(Dir["#{dir}/bin/*"], dir)
end
def make
_, which_status = Gitlab::Popen.popen(%w[which gmake])
which_status == 0 ? 'gmake' : 'make'
end
end
end
......
......@@ -26,14 +26,7 @@ namespace :gitlab do
args.with_defaults(repo: 'https://gitlab.com/gitlab-org/gitlab-workhorse.git')
checkout_or_clone_version(version: 'workhorse-move-notice', repo: args.repo, target_dir: args.dir, clone_opts: %w[--depth 1])
_, which_status = Gitlab::Popen.popen(%w[which gmake])
make = which_status == 0 ? 'gmake' : 'make'
command = %W[#{make} -C #{Rails.root.join('workhorse')} install PREFIX=#{File.absolute_path(args.dir)}]
run_command!(command)
# 'make install' puts the binaries in #{args.dir}/bin but the init script expects them in args.dir
FileUtils.mv(Dir["#{args.dir}/bin/*"], args.dir)
Gitlab::SetupHelper::Workhorse.compile_into(args.dir)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::SetupHelper::Workhorse do
describe '.make' do
subject { described_class.make }
context 'when there is a gmake' do
it 'returns gmake' do
expect(Gitlab::Popen).to receive(:popen).with(%w[which gmake]).and_return(['/usr/bin/gmake', 0])
expect(subject).to eq 'gmake'
end
end
context 'when there is no gmake' do
it 'returns make' do
expect(Gitlab::Popen).to receive(:popen).with(%w[which gmake]).and_return(['', 1])
expect(subject).to eq 'make'
end
end
end
end
......@@ -241,15 +241,14 @@ module TestEnv
end
def setup_workhorse
install_workhorse_args = [workhorse_dir, workhorse_url].compact.join(',')
component_timed_setup(
'GitLab Workhorse',
install_dir: workhorse_dir,
version: Gitlab::Workhorse.version,
task: "gitlab:workhorse:install[#{install_workhorse_args}]") do
Gitlab::SetupHelper::Workhorse.create_configuration(workhorse_dir, nil)
end
start = Time.now
puts "\n==> Setting up GitLab Workhorse..."
FileUtils.rm_rf(workhorse_dir)
Gitlab::SetupHelper::Workhorse.compile_into(workhorse_dir)
Gitlab::SetupHelper::Workhorse.create_configuration(workhorse_dir, nil)
puts " GitLab Workhorse set up in #{Time.now - start} seconds...\n"
end
def workhorse_dir
......
......@@ -9,9 +9,13 @@ RSpec.describe 'gitlab:workhorse namespace rake task' do
describe 'install' do
let(:repo) { 'https://gitlab.com/gitlab-org/gitlab-workhorse.git' }
let(:clone_path) { Rails.root.join('tmp/tests/gitlab-workhorse').to_s }
let(:clone_path) { Dir.mktmpdir('gitlab:workhorse:install-rake-test') }
let(:workhorse_source) { Rails.root.join('workhorse').to_s }
after do
FileUtils.rm_rf(clone_path)
end
context 'no dir given' do
it 'aborts and display a help message' do
# avoid writing task output to spec progress
......@@ -20,7 +24,7 @@ RSpec.describe 'gitlab:workhorse namespace rake task' do
end
end
context 'when an underlying Git command fail' do
context 'when an underlying Git command fails' do
it 'aborts and display a help message' do
expect(main_object)
.to receive(:checkout_or_clone_version).and_raise 'Git error'
......@@ -29,47 +33,26 @@ RSpec.describe 'gitlab:workhorse namespace rake task' do
end
end
describe 'checkout or clone' do
it 'calls checkout_or_clone_version with the right arguments' do
expect(main_object)
.to receive(:checkout_or_clone_version).with(version: 'workhorse-move-notice', repo: repo, target_dir: clone_path, clone_opts: %w[--depth 1])
run_rake_task('gitlab:workhorse:install', clone_path)
end
end
describe 'gmake/make' do
before do
FileUtils.mkdir_p(clone_path)
end
context 'gmake is available' do
before do
expect(main_object).to receive(:checkout_or_clone_version)
allow(Object).to receive(:run_command!).with(['gmake']).and_return(true)
it 'clones the origin and creates a gitlab-workhorse binary' do
FileUtils.rm_rf(clone_path)
Dir.mktmpdir('fake-workhorse-origin') do |workhorse_origin|
[
%W[git init -q #{workhorse_origin}],
%W[git -C #{workhorse_origin} checkout -q -b workhorse-move-notice],
%W[touch #{workhorse_origin}/proof-that-repo-got-cloned],
%W[git -C #{workhorse_origin} add .],
%W[git -C #{workhorse_origin} commit -q -m init],
%W[git -C #{workhorse_origin} checkout -q -b master]
].each do |cmd|
raise "#{cmd.join(' ')} failed" unless system(*cmd)
end
it 'calls gmake in the gitlab-workhorse directory' do
expect(Gitlab::Popen).to receive(:popen).with(%w[which gmake]).and_return(['/usr/bin/gmake', 0])
expect(main_object).to receive(:run_command!).with(["gmake", "-C", workhorse_source, "install", "PREFIX=#{clone_path}"]).and_return(true)
run_rake_task('gitlab:workhorse:install', clone_path)
end
run_rake_task('gitlab:workhorse:install', clone_path, File.join(workhorse_origin, '.git'))
end
context 'gmake is not available' do
before do
expect(main_object).to receive(:checkout_or_clone_version)
allow(main_object).to receive(:run_command!).with(['make']).and_return(true)
end
it 'calls make in the gitlab-workhorse directory' do
expect(Gitlab::Popen).to receive(:popen).with(%w[which gmake]).and_return(['', 42])
expect(main_object).to receive(:run_command!).with(["make", "-C", workhorse_source, "install", "PREFIX=#{clone_path}"]).and_return(true)
run_rake_task('gitlab:workhorse:install', clone_path)
end
end
expect(File.exist?(File.join(clone_path, 'proof-that-repo-got-cloned'))).to be true
expect(File.executable?(File.join(clone_path, 'gitlab-workhorse'))).to be true
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