Commit 5c6ae5e3 authored by Alex Kalderimis's avatar Alex Kalderimis Committed by Robert Speicher

Allow tests to be quiet

Our tests print a lot of repetitive guff that is helpful in debugging
circumstances, but otherwise gets in the way. This change allows
(opt-in) for a developer to turn off these messages by setting
`GITLAB_TESTING_QUIET` to anything other than `"false"`.
parent ca520887
......@@ -6,8 +6,16 @@
require 'securerandom'
require 'socket'
require 'logger'
module GitalyTest
LOGGER = begin
default_name = ENV['CI'] ? 'DEBUG' : 'WARN'
level_name = ENV['GITLAB_TESTING_LOG_LEVEL']&.upcase
level = Logger.const_get(level_name || default_name, true) # rubocop: disable Gitlab/ConstGetInheritFalse
Logger.new(STDOUT, level: level, formatter: ->(_, _, _, msg) { msg })
end
def tmp_tests_gitaly_dir
File.expand_path('../tmp/tests/gitaly', __dir__)
end
......@@ -98,7 +106,7 @@ module GitalyTest
end
def check_gitaly_config!
puts "Checking gitaly-ruby Gemfile..."
LOGGER.debug "Checking gitaly-ruby Gemfile...\n"
unless File.exist?(gemfile)
message = "#{gemfile} does not exist."
......@@ -106,8 +114,9 @@ module GitalyTest
abort message
end
puts 'Checking gitaly-ruby bundle...'
abort 'bundle check failed' unless system(env, 'bundle', 'check', chdir: File.dirname(gemfile))
LOGGER.debug "Checking gitaly-ruby bundle...\n"
out = ENV['CI'] ? STDOUT : '/dev/null'
abort 'bundle check failed' unless system(env, 'bundle', 'check', out: out, chdir: File.dirname(gemfile))
end
def read_socket_path(service)
......@@ -126,22 +135,22 @@ module GitalyTest
end
def try_connect!(service)
print "Trying to connect to #{service}: "
LOGGER.debug "Trying to connect to #{service}: "
timeout = 20
delay = 0.1
socket = read_socket_path(service)
Integer(timeout / delay).times do
UNIXSocket.new(socket)
puts ' OK'
LOGGER.debug " OK\n"
return
rescue Errno::ENOENT, Errno::ECONNREFUSED
print '.'
LOGGER.debug '.'
sleep delay
end
puts ' FAILED'
LOGGER.warn " FAILED to connect to #{service}\n"
raise "could not connect to #{socket}"
end
......
......@@ -169,8 +169,9 @@ module TestEnv
task: "gitlab:gitaly:install[#{install_gitaly_args}]") do
Gitlab::SetupHelper::Gitaly.create_configuration(gitaly_dir, { 'default' => repos_path }, force: true)
Gitlab::SetupHelper::Praefect.create_configuration(gitaly_dir, { 'praefect' => repos_path }, force: true)
start_gitaly(gitaly_dir)
end
start_gitaly(gitaly_dir)
end
def gitaly_socket_path
......@@ -463,7 +464,6 @@ module TestEnv
end
def component_timed_setup(component, install_dir:, version:, task:)
puts "\n==> Setting up #{component}..."
start = Time.now
ensure_component_dir_name_is_correct!(component, install_dir)
......@@ -472,22 +472,22 @@ module TestEnv
return if File.exist?(install_dir) && ci?
if component_needs_update?(install_dir, version)
puts "\n==> Setting up #{component}..."
# Cleanup the component entirely to ensure we start fresh
FileUtils.rm_rf(install_dir)
unless system('rake', task)
raise ComponentFailedToInstallError
end
end
yield if block_given?
puts " #{component} set up in #{Time.now - start} seconds...\n"
end
rescue ComponentFailedToInstallError
puts "\n#{component} failed to install, cleaning up #{install_dir}!\n"
FileUtils.rm_rf(install_dir)
exit 1
ensure
puts " #{component} set up in #{Time.now - start} seconds...\n"
end
def ci?
......
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