Commit c236b208 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'improve-before-all-adapter' into 'master'

Improve `BeforeAllAdapter` support

See merge request gitlab-org/gitlab!70593
parents d424fb9e 8ba2a598
# frozen_string_literal: true
class BeforeAllAdapter # rubocop:disable Gitlab/NamespacedClass
def self.all_connection_pools
::ActiveRecord::Base.connection_handler.all_connection_pools
def self.all_connection_classes
@all_connection_classes ||= [ActiveRecord::Base] + ActiveRecord::Base.descendants.select(&:connection_class?) # rubocop: disable Database/MultipleDatabases
end
def self.begin_transaction
self.all_connection_pools.each do |connection_pool|
connection_pool.connection.begin_transaction(joinable: false)
self.all_connection_classes.each do |connection_class|
connection_class.connection.begin_transaction(joinable: false)
end
end
def self.rollback_transaction
self.all_connection_pools.each do |connection_pool|
if connection_pool.connection.open_transactions.zero?
self.all_connection_classes.each do |connection_class|
if connection_class.connection.open_transactions.zero?
warn "!!! before_all transaction has been already rollbacked and " \
"could work incorrectly"
next
end
connection_pool.connection.rollback_transaction
connection_class.connection.rollback_transaction
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment