debian-mirror-gitlab/spec/support/database/prevent_cross_database_modification.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
1.3 KiB
Ruby
Raw Normal View History

2021-10-27 15:23:28 +05:30
# frozen_string_literal: true
2021-12-11 22:18:48 +05:30
module PreventCrossDatabaseModificationSpecHelpers
delegate :with_cross_database_modification_prevented,
:allow_cross_database_modification_within_transaction,
to: :'::Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification'
2021-10-27 15:23:28 +05:30
end
2021-11-18 22:05:49 +05:30
CROSS_DB_MODIFICATION_ALLOW_LIST = Set.new(YAML.load_file(File.join(__dir__, 'cross-database-modification-allowlist.yml'))).freeze
2021-10-27 15:23:28 +05:30
RSpec.configure do |config|
2021-12-11 22:18:48 +05:30
config.include(PreventCrossDatabaseModificationSpecHelpers)
# By default allow cross-modifications as we want to observe only transactions
# within a specific block of execution which is defined be `before(:each)` and `after(:each)`
config.before(:all) do
::Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification.suppress = true
end
2021-10-27 15:23:28 +05:30
# Using before and after blocks because the around block causes problems with the let_it_be
# record creations. It makes an extra savepoint which breaks the transaction count logic.
2021-11-18 22:05:49 +05:30
config.before do |example_file|
2021-12-11 22:18:48 +05:30
::Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification.suppress =
CROSS_DB_MODIFICATION_ALLOW_LIST.include?(example_file.file_path_rerun_argument)
2021-10-27 15:23:28 +05:30
end
2021-12-11 22:18:48 +05:30
# Reset after execution to preferred state
2021-11-18 22:05:49 +05:30
config.after do |example_file|
2021-12-11 22:18:48 +05:30
::Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification.suppress = true
2021-10-27 15:23:28 +05:30
end
end