From ed8667df5cd4d4026d803b59e6a8f1af910ae3e3 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 27 Apr 2021 09:34:41 +0200 Subject: [PATCH] Silence assert_slower_by_at_most by default Tests shouldn't have any output if they pass. --- activerecord/test/cases/encryption/helper.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/activerecord/test/cases/encryption/helper.rb b/activerecord/test/cases/encryption/helper.rb index 926b15f834..81377326b4 100644 --- a/activerecord/test/cases/encryption/helper.rb +++ b/activerecord/test/cases/encryption/helper.rb @@ -112,7 +112,7 @@ module ActiveRecord::Encryption # assert_slower_by_at_most 2, baseline: baseline do # # end - def assert_slower_by_at_most(threshold_factor, baseline:, baseline_label: BASELINE_LABEL, code_to_test_label: CODE_TO_TEST_LABEL, duration: BENCHMARK_DURATION, quiet: false, &block_to_test) + def assert_slower_by_at_most(threshold_factor, baseline:, baseline_label: BASELINE_LABEL, code_to_test_label: CODE_TO_TEST_LABEL, duration: BENCHMARK_DURATION, quiet: true, &block_to_test) GC.start result = nil @@ -125,13 +125,15 @@ module ActiveRecord::Encryption end end - puts "#{output}#{error}" unless quiet - baseline_result = result.entries.find { |entry| entry.label == baseline_label } code_to_test_result = result.entries.find { |entry| entry.label == code_to_test_label } times_slower = baseline_result.ips / code_to_test_result.ips + if !quiet || times_slower >= threshold_factor + puts "#{output}#{error}" + end + assert times_slower < threshold_factor, "Expecting #{threshold_factor} times slower at most, but got #{times_slower} times slower" end end