Skip to content

Commit

Permalink
Merge pull request #50986 from Shopify/delete-encryption-performance-…
Browse files Browse the repository at this point in the history
…tests

Delete `EncryptionPerformanceTest`
  • Loading branch information
byroot committed Feb 6, 2024
2 parents ed2e77d + 3e7ba58 commit f0d433b
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 233 deletions.
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ group :test do
gem "debug", ">= 1.1.0", require: false
end

gem "benchmark-ips"

# Needed for Railties tests because it is included in generated apps.
gem "brakeman"
end
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ GEM
base64 (0.2.0)
bcrypt (3.1.20)
beaneater (1.1.3)
benchmark-ips (2.13.0)
bigdecimal (3.1.5)
bindex (0.8.1)
bootsnap (1.17.0)
Expand Down Expand Up @@ -596,7 +595,6 @@ DEPENDENCIES
azure-storage-blob (~> 2.0)
backburner
bcrypt (~> 3.1.11)
benchmark-ips
bootsnap (>= 1.4.4)
brakeman
capybara (>= 3.39)
Expand Down
42 changes: 1 addition & 41 deletions activerecord/test/cases/encryption/helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "cases/helper"
require "benchmark/ips"

class ActiveRecord::Fixture
prepend ActiveRecord::Encryption::EncryptedFixtures
Expand Down Expand Up @@ -111,45 +110,6 @@ def assert_invalid_key_cant_read_attribute_with_custom_key_provider(model, attri
attribute_type.key_provider.keys = original_keys
end
end

module PerformanceHelpers
BENCHMARK_DURATION = 1
BENCHMARK_WARMUP = 1
BASELINE_LABEL = "Baseline"
CODE_TO_TEST_LABEL = "Code"

# Usage:
#
# baseline = -> { <some baseline code> }
#
# assert_slower_by_at_most 2, baseline: baseline do
# <the code you want to compare against the baseline>
# 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: true, &block_to_test)
GC.start

result = nil
output, error = capture_io do
result = Benchmark.ips do |x|
x.config(time: duration, warmup: BENCHMARK_WARMUP)
x.report(code_to_test_label, &block_to_test)
x.report(baseline_label, &baseline)
x.compare!
end
end

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
end

# We eager load encrypted attribute types as they are declared, so that they pick up the
Expand All @@ -163,7 +123,7 @@ def assert_slower_by_at_most(threshold_factor, baseline:, baseline_label: BASELI
end

class ActiveRecord::EncryptionTestCase < ActiveRecord::TestCase
include ActiveRecord::Encryption::EncryptionHelpers, ActiveRecord::Encryption::PerformanceHelpers
include ActiveRecord::Encryption::EncryptionHelpers

ENCRYPTION_PROPERTIES_TO_RESET = {
config: %i[ primary_key deterministic_key key_derivation_salt store_key_references hash_digest_class
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit f0d433b

Please sign in to comment.