diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/support/before_all_adapter.rb | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/support/before_all_adapter.rb')
-rw-r--r-- | spec/support/before_all_adapter.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/support/before_all_adapter.rb b/spec/support/before_all_adapter.rb new file mode 100644 index 00000000000..f48e0f46e80 --- /dev/null +++ b/spec/support/before_all_adapter.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class BeforeAllAdapter # rubocop:disable Gitlab/NamespacedClass + def self.all_connection_pools + ::ActiveRecord::Base.connection_handler.all_connection_pools + end + + def self.begin_transaction + self.all_connection_pools.each do |connection_pool| + connection_pool.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? + warn "!!! before_all transaction has been already rollbacked and " \ + "could work incorrectly" + next + end + + connection_pool.connection.rollback_transaction + end + end +end + +TestProf::BeforeAll.adapter = ::BeforeAllAdapter |