2018-05-14 04:10:29 -04:00
|
|
|
# This file contains environment settings for gitaly when it's running
|
|
|
|
# as part of the gitlab-ce/ee test suite.
|
|
|
|
#
|
|
|
|
# Please be careful when modifying this file. Your changes must work
|
|
|
|
# both for local development rspec runs, and in CI.
|
|
|
|
|
|
|
|
require 'socket'
|
|
|
|
|
|
|
|
module GitalyTest
|
|
|
|
def tmp_tests_gitaly_dir
|
|
|
|
File.expand_path('../tmp/tests/gitaly', __dir__)
|
|
|
|
end
|
|
|
|
|
|
|
|
def gemfile
|
|
|
|
File.join(tmp_tests_gitaly_dir, 'ruby', 'Gemfile')
|
|
|
|
end
|
|
|
|
|
|
|
|
def env
|
|
|
|
env_hash = {
|
|
|
|
'HOME' => File.expand_path('tmp/tests'),
|
|
|
|
'GEM_PATH' => Gem.path.join(':'),
|
|
|
|
'BUNDLE_APP_CONFIG' => File.join(File.dirname(gemfile), '.bundle/config'),
|
|
|
|
'BUNDLE_FLAGS' => "--jobs=4 --retry=3",
|
|
|
|
'BUNDLE_INSTALL_FLAGS' => nil,
|
|
|
|
'BUNDLE_GEMFILE' => gemfile,
|
2019-06-06 06:05:11 -04:00
|
|
|
'RUBYOPT' => nil,
|
|
|
|
|
|
|
|
# Git hooks can't run during tests as the internal API is not running.
|
|
|
|
'GITALY_TESTING_NO_GIT_HOOKS' => "1"
|
2018-05-14 04:10:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ENV['CI']
|
|
|
|
bundle_path = File.expand_path('../vendor/gitaly-ruby', __dir__)
|
|
|
|
env_hash['BUNDLE_FLAGS'] << " --path=#{bundle_path}"
|
|
|
|
end
|
|
|
|
|
|
|
|
env_hash
|
|
|
|
end
|
|
|
|
|
2020-03-25 14:08:10 -04:00
|
|
|
def config_path(service)
|
|
|
|
case service
|
|
|
|
when :gitaly
|
|
|
|
File.join(tmp_tests_gitaly_dir, 'config.toml')
|
|
|
|
when :praefect
|
|
|
|
File.join(tmp_tests_gitaly_dir, 'praefect.config.toml')
|
|
|
|
end
|
2018-05-14 04:10:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def start_gitaly
|
2020-03-25 14:08:10 -04:00
|
|
|
start(:gitaly)
|
|
|
|
end
|
|
|
|
|
|
|
|
def start_praefect
|
|
|
|
start(:praefect)
|
|
|
|
end
|
|
|
|
|
|
|
|
def start(service)
|
|
|
|
args = ["#{tmp_tests_gitaly_dir}/#{service}"]
|
|
|
|
args.push("-config") if service == :praefect
|
|
|
|
args.push(config_path(service))
|
|
|
|
pid = spawn(env, *args, [:out, :err] => "log/#{service}-test.log")
|
2018-05-14 04:10:29 -04:00
|
|
|
|
|
|
|
begin
|
2020-03-25 14:08:10 -04:00
|
|
|
try_connect!(service)
|
2018-05-14 04:10:29 -04:00
|
|
|
rescue
|
|
|
|
Process.kill('TERM', pid)
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
|
|
|
|
pid
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_gitaly_config!
|
2019-12-10 02:53:40 -05:00
|
|
|
puts "Checking gitaly-ruby Gemfile..."
|
|
|
|
|
|
|
|
unless File.exist?(gemfile)
|
|
|
|
message = "#{gemfile} does not exist."
|
|
|
|
message += "\n\nThis might have happened if the CI artifacts for this build were destroyed." if ENV['CI']
|
|
|
|
abort message
|
|
|
|
end
|
|
|
|
|
2018-05-14 04:10:29 -04:00
|
|
|
puts 'Checking gitaly-ruby bundle...'
|
|
|
|
abort 'bundle check failed' unless system(env, 'bundle', 'check', chdir: File.dirname(gemfile))
|
|
|
|
end
|
|
|
|
|
2020-03-25 14:08:10 -04:00
|
|
|
def read_socket_path(service)
|
2018-05-14 04:10:29 -04:00
|
|
|
# This code needs to work in an environment where we cannot use bundler,
|
|
|
|
# so we cannot easily use the toml-rb gem. This ad-hoc parser should be
|
|
|
|
# good enough.
|
2020-03-25 14:08:10 -04:00
|
|
|
config_text = IO.read(config_path(service))
|
2018-05-14 04:10:29 -04:00
|
|
|
|
|
|
|
config_text.lines.each do |line|
|
|
|
|
match_data = line.match(/^\s*socket_path\s*=\s*"([^"]*)"$/)
|
|
|
|
|
|
|
|
return match_data[1] if match_data
|
|
|
|
end
|
|
|
|
|
2020-03-25 14:08:10 -04:00
|
|
|
raise "failed to find socket_path in #{config_path(service)}"
|
2018-05-14 04:10:29 -04:00
|
|
|
end
|
|
|
|
|
2020-03-25 14:08:10 -04:00
|
|
|
def try_connect!(service)
|
|
|
|
print "Trying to connect to #{service}: "
|
2018-05-14 04:10:29 -04:00
|
|
|
timeout = 20
|
|
|
|
delay = 0.1
|
2020-03-25 14:08:10 -04:00
|
|
|
socket = read_socket_path(service)
|
2018-05-14 04:10:29 -04:00
|
|
|
|
|
|
|
Integer(timeout / delay).times do
|
2019-03-13 09:42:43 -04:00
|
|
|
UNIXSocket.new(socket)
|
|
|
|
puts ' OK'
|
|
|
|
|
|
|
|
return
|
|
|
|
rescue Errno::ENOENT, Errno::ECONNREFUSED
|
|
|
|
print '.'
|
|
|
|
sleep delay
|
2018-05-14 04:10:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
puts ' FAILED'
|
|
|
|
|
|
|
|
raise "could not connect to #{socket}"
|
|
|
|
end
|
|
|
|
end
|