Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test flakiness introduced in encryption tests #48659

Merged
merged 1 commit into from Jul 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -179,6 +179,6 @@ def declare_class_with_global_previous_encryption_schemes(*previous_schemes)
self.table_name = "authors"

encrypts :name
end
end.tap { |klass| klass.type_for_attribute(:name) }
end
end
10 changes: 10 additions & 0 deletions activerecord/test/cases/encryption/helper.rb
Expand Up @@ -152,6 +152,16 @@ def assert_slower_by_at_most(threshold_factor, baseline:, baseline_label: BASELI
end
end

# We eager load encrypted attribute types as they are declared, so that they pick up the
# default encryption setup for tests. Because we load those lazily when used, this prevents
# side effects where some tests modify encryption config settings affecting others.
#
# Notice that we clear the declaration listeners when each test start, so this will only affect
# the classes loaded before tests starts, not those declared during tests.
ActiveRecord::Encryption.on_encrypted_attribute_declared do |klass, attribute_name|
klass.type_for_attribute(attribute_name)
end

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

Expand Down