Commit 9a7b4506 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'ajk-quiet-tests' into 'master'

Allow tests to be quiet

See merge request gitlab-org/gitlab!34020
parents 63986a76 5c6ae5e3
...@@ -6,8 +6,16 @@ ...@@ -6,8 +6,16 @@
require 'securerandom' require 'securerandom'
require 'socket' require 'socket'
require 'logger'
module GitalyTest 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 def tmp_tests_gitaly_dir
File.expand_path('../tmp/tests/gitaly', __dir__) File.expand_path('../tmp/tests/gitaly', __dir__)
end end
...@@ -98,7 +106,7 @@ module GitalyTest ...@@ -98,7 +106,7 @@ module GitalyTest
end end
def check_gitaly_config! def check_gitaly_config!
puts "Checking gitaly-ruby Gemfile..." LOGGER.debug "Checking gitaly-ruby Gemfile...\n"
unless File.exist?(gemfile) unless File.exist?(gemfile)
message = "#{gemfile} does not exist." message = "#{gemfile} does not exist."
...@@ -106,8 +114,9 @@ module GitalyTest ...@@ -106,8 +114,9 @@ module GitalyTest
abort message abort message
end end
puts 'Checking gitaly-ruby bundle...' LOGGER.debug "Checking gitaly-ruby bundle...\n"
abort 'bundle check failed' unless system(env, 'bundle', 'check', chdir: File.dirname(gemfile)) out = ENV['CI'] ? STDOUT : '/dev/null'
abort 'bundle check failed' unless system(env, 'bundle', 'check', out: out, chdir: File.dirname(gemfile))
end end
def read_socket_path(service) def read_socket_path(service)
...@@ -126,22 +135,22 @@ module GitalyTest ...@@ -126,22 +135,22 @@ module GitalyTest
end end
def try_connect!(service) def try_connect!(service)
print "Trying to connect to #{service}: " LOGGER.debug "Trying to connect to #{service}: "
timeout = 20 timeout = 20
delay = 0.1 delay = 0.1
socket = read_socket_path(service) socket = read_socket_path(service)
Integer(timeout / delay).times do Integer(timeout / delay).times do
UNIXSocket.new(socket) UNIXSocket.new(socket)
puts ' OK' LOGGER.debug " OK\n"
return return
rescue Errno::ENOENT, Errno::ECONNREFUSED rescue Errno::ENOENT, Errno::ECONNREFUSED
print '.' LOGGER.debug '.'
sleep delay sleep delay
end end
puts ' FAILED' LOGGER.warn " FAILED to connect to #{service}\n"
raise "could not connect to #{socket}" raise "could not connect to #{socket}"
end end
......
...@@ -169,8 +169,9 @@ module TestEnv ...@@ -169,8 +169,9 @@ module TestEnv
task: "gitlab:gitaly:install[#{install_gitaly_args}]") do task: "gitlab:gitaly:install[#{install_gitaly_args}]") do
Gitlab::SetupHelper::Gitaly.create_configuration(gitaly_dir, { 'default' => repos_path }, force: true) Gitlab::SetupHelper::Gitaly.create_configuration(gitaly_dir, { 'default' => repos_path }, force: true)
Gitlab::SetupHelper::Praefect.create_configuration(gitaly_dir, { 'praefect' => repos_path }, force: true) Gitlab::SetupHelper::Praefect.create_configuration(gitaly_dir, { 'praefect' => repos_path }, force: true)
start_gitaly(gitaly_dir)
end end
start_gitaly(gitaly_dir)
end end
def gitaly_socket_path def gitaly_socket_path
...@@ -463,7 +464,6 @@ module TestEnv ...@@ -463,7 +464,6 @@ module TestEnv
end end
def component_timed_setup(component, install_dir:, version:, task:) def component_timed_setup(component, install_dir:, version:, task:)
puts "\n==> Setting up #{component}..."
start = Time.now start = Time.now
ensure_component_dir_name_is_correct!(component, install_dir) ensure_component_dir_name_is_correct!(component, install_dir)
...@@ -472,22 +472,22 @@ module TestEnv ...@@ -472,22 +472,22 @@ module TestEnv
return if File.exist?(install_dir) && ci? return if File.exist?(install_dir) && ci?
if component_needs_update?(install_dir, version) if component_needs_update?(install_dir, version)
puts "\n==> Setting up #{component}..."
# Cleanup the component entirely to ensure we start fresh # Cleanup the component entirely to ensure we start fresh
FileUtils.rm_rf(install_dir) FileUtils.rm_rf(install_dir)
unless system('rake', task) unless system('rake', task)
raise ComponentFailedToInstallError raise ComponentFailedToInstallError
end end
end
yield if block_given? yield if block_given?
puts " #{component} set up in #{Time.now - start} seconds...\n"
end
rescue ComponentFailedToInstallError rescue ComponentFailedToInstallError
puts "\n#{component} failed to install, cleaning up #{install_dir}!\n" puts "\n#{component} failed to install, cleaning up #{install_dir}!\n"
FileUtils.rm_rf(install_dir) FileUtils.rm_rf(install_dir)
exit 1 exit 1
ensure
puts " #{component} set up in #{Time.now - start} seconds...\n"
end end
def ci? 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