Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions bin/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ copy_in_saver_test_data()

containers_down()
{
docker compose down --remove-orphans --volumes
local -r all=$(docker ps --all --quiet)
if [ -n "${all}" ]; then
# shellcheck disable=SC2086
docker rm --force ${all}
fi
}

echo_warnings()
Expand Down Expand Up @@ -95,10 +99,11 @@ remove_all_but_latest()
# Keep latest in the cache
local -r docker_image_ls="${1}"
local -r name="${2}"
docker container prune --force
for image_name in $(echo "${docker_image_ls}" | grep "${name}:")
do
if [ "${image_name}" != "${name}:latest" ]; then
docker image rm "${image_name}"
docker image rm --force "${image_name}"
fi
done
docker system prune --force
Expand Down
1 change: 1 addition & 0 deletions bin/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ check_args()
run_tests()
{
check_args "$@"
containers_down

local -r TYPE="${1}" # {server|client}
local -r TEST_LOG=test.log
Expand Down
2 changes: 2 additions & 0 deletions source/server/config/puma.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env puma
require 'etc'

environment('production')
rackup("#{__dir__}/config.ru")
workers(Etc.nprocessors)
2 changes: 1 addition & 1 deletion test/client/lib/coverage_metrics_limits.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def metrics
[
[ nil ],
[ 'test.lines.total' , '<=', 230 ],
[ 'test.lines.total' , '<=', 243 ],
[ 'test.lines.missed' , '<=', 0 ],
[ 'test.branches.total' , '<=', 0 ],
[ 'test.branches.missed', '<=', 0 ],
Expand Down
21 changes: 4 additions & 17 deletions test/client/lib/id58_test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
require 'minitest/autorun'
require 'minitest/reporters'
require_relative 'slim_json_reporter'
require_relative 'slow_tests_reporter'

Minitest.parallel_executor = Minitest::Parallel::Executor.new(Etc.nprocessors)

reporters = [
Minitest::Reporters::DefaultReporter.new,
Minitest::Reporters::SlimJsonReporter.new,
Minitest::Reporters::JUnitReporter.new("#{ENV.fetch('COVERAGE_ROOT')}/junit")
Minitest::Reporters::JUnitReporter.new("#{ENV.fetch('COVERAGE_ROOT')}/junit"),
Minitest::Reporters::SlowTestsReporter.new
]
Minitest::Reporters.use!(reporters)

Expand All @@ -28,8 +30,6 @@ def initialize(arg)

@@args = (ARGV.sort.uniq - ['--']) # eg 2m4
@@seen_ids = []
@@timings = {}
TIMINGS_LOCK = Mutex.new

def self.test(id58, *lines, &test_block)
src = test_block.source_location
Expand All @@ -47,7 +47,7 @@ def self.test(id58, *lines, &test_block)
t1 = Time.now
instance_eval(&test_block)
t2 = Time.now
TIMINGS_LOCK.synchronize { @@timings["#{id58}:#{src_file}:#{src_line}:#{name58}"] = (t2 - t1) }
SlowTestsTimings::LOCK.synchronize { SlowTestsTimings::TIMINGS["#{id58}:#{src_file}:#{src_line}:#{name58}"] = (t2 - t1) }
ensure
puts $ERROR_INFO.message unless $ERROR_INFO.nil?
id58_teardown
Expand All @@ -57,19 +57,6 @@ def self.test(id58, *lines, &test_block)
define_method("test_\n#{name}".to_sym, &execute_around)
end

Minitest.after_run do
slow = @@timings.select { |_name, secs| secs > 0.000 }
sorted = slow.sort_by { |_name, secs| -secs }.to_h
size = [sorted.size, 5].min
puts
puts 'Slowest tests are...' unless sorted.empty?
sorted.each_with_index do |(name, secs), index|
puts format('%3.4f - %-72s', secs, name)
break if index == size
end
puts
end

ID58_ALPHABET = %w[
0 1 2 3 4 5 6 7 8 9
A B C D E F G H J K L M N P Q R S T U V W X Y Z
Expand Down
20 changes: 20 additions & 0 deletions test/client/lib/slow_tests_reporter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'minitest/reporters'

module SlowTestsTimings
TIMINGS = {}
LOCK = Mutex.new
end

class Minitest::Reporters::SlowTestsReporter < Minitest::Reporters::BaseReporter
def report
# Prints the 5 slowest tests by duration after the full test run.
super
sorted = SlowTestsTimings::TIMINGS.sort_by { |_name, secs| -secs }.first(5)
puts
puts 'Slowest tests are...'
sorted.each do |(name, secs)|
puts format('%3.4f %-72s', secs, name)
end
puts
end
end
2 changes: 1 addition & 1 deletion test/server/lib/coverage_metrics_limits.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def metrics
[
[ nil ],
[ 'test.lines.total' , '<=', 531 ],
[ 'test.lines.total' , '<=', 544 ],
[ 'test.lines.missed' , '<=', 0 ],
[ 'test.branches.total' , '<=', 0 ],
[ 'test.branches.missed', '<=', 0 ],
Expand Down
21 changes: 4 additions & 17 deletions test/server/lib/id58_test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
require 'minitest/autorun'
require 'minitest/reporters'
require_relative 'slim_json_reporter'
require_relative 'slow_tests_reporter'

Minitest.parallel_executor = Minitest::Parallel::Executor.new(Etc.nprocessors)

reporters = [
Minitest::Reporters::DefaultReporter.new,
Minitest::Reporters::SlimJsonReporter.new,
Minitest::Reporters::JUnitReporter.new("#{ENV.fetch('COVERAGE_ROOT')}/junit")
Minitest::Reporters::JUnitReporter.new("#{ENV.fetch('COVERAGE_ROOT')}/junit"),
Minitest::Reporters::SlowTestsReporter.new
]
Minitest::Reporters.use!(reporters)

Expand All @@ -28,8 +30,6 @@ def initialize(arg)

@@args = (ARGV.sort.uniq - ['--']) # eg 2m4
@@seen_ids = []
@@timings = {}
TIMINGS_LOCK = Mutex.new

def self.test(id58, *lines, &test_block)
src = test_block.source_location
Expand All @@ -47,7 +47,7 @@ def self.test(id58, *lines, &test_block)
t1 = Time.now
instance_eval(&test_block)
t2 = Time.now
TIMINGS_LOCK.synchronize { @@timings["#{id58}:#{src_file}:#{src_line}:#{name58}"] = (t2 - t1) }
SlowTestsTimings::LOCK.synchronize { SlowTestsTimings::TIMINGS["#{id58}:#{src_file}:#{src_line}:#{name58}"] = (t2 - t1) }
ensure
puts $ERROR_INFO.message unless $ERROR_INFO.nil?
id58_teardown
Expand All @@ -57,19 +57,6 @@ def self.test(id58, *lines, &test_block)
define_method("test_\n#{name}".to_sym, &execute_around)
end

Minitest.after_run do
slow = @@timings.select { |_name, secs| secs > 0.000 }
sorted = slow.sort_by { |_name, secs| -secs }.to_h
size = [sorted.size, 5].min
puts
puts 'Slowest tests are...' unless sorted.empty?
sorted.each_with_index do |(name, secs), index|
puts format('%3.4f - %-72s', secs, name)
break if index == size
end
puts
end

ID58_ALPHABET = %w[
0 1 2 3 4 5 6 7 8 9
A B C D E F G H J K L M N P Q R S T U V W X Y Z
Expand Down
20 changes: 20 additions & 0 deletions test/server/lib/slow_tests_reporter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'minitest/reporters'

module SlowTestsTimings
TIMINGS = {}
LOCK = Mutex.new
end

class Minitest::Reporters::SlowTestsReporter < Minitest::Reporters::BaseReporter
def report
# Prints the 5 slowest tests by duration after the full test run.
super
sorted = SlowTestsTimings::TIMINGS.sort_by { |_name, secs| -secs }.first(5)
puts
puts 'Slowest tests are...'
sorted.each do |(name, secs)|
puts format('%3.4f %-72s', secs, name)
end
puts
end
end
Loading