Skip to content
Snippets Groups Projects
Verified Commit f6312a04 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu
Browse files

Fix order-dependent test failures

Prevent extra DB connection pools from leaking to succeeding tests and
also improves our connection check initializer so that it works even
with multiple connection pools for the same DB name.
parent 35fc7c81
No related branches found
No related tags found
2 merge requests!162233Draft: Script to update Topology Service Gem,!153811Fix order-dependent test failures
......@@ -12,15 +12,15 @@ def self.raise_if_new_database_connection
return yield if Gitlab::Utils.to_boolean(ENV['SKIP_RAISE_ON_INITIALIZE_CONNECTIONS'])
previous_connection_counts =
ActiveRecord::Base.connection_handler.connection_pool_list(ApplicationRecord.current_role).to_h do |pool|
[pool.db_config.name, pool.connections.size]
ActiveRecord::Base.connection_handler.connection_pool_list(ApplicationRecord.current_role).map do |pool|
pool.connections.size
end
yield
new_connection_counts =
ActiveRecord::Base.connection_handler.connection_pool_list(ApplicationRecord.current_role).to_h do |pool|
[pool.db_config.name, pool.connections.size]
ActiveRecord::Base.connection_handler.connection_pool_list(ApplicationRecord.current_role).map do |pool|
pool.connections.size
end
raise_database_connection_made_error unless previous_connection_counts == new_connection_counts
......
......@@ -37,14 +37,13 @@ def block_with_error
expect { block_with_database_call }.not_to raise_error
end
it 'prevents any database connection if SKIP_RAISE_ON_INITIALIZE_CONNECTIONS is false',
quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/444962' do
it 'prevents any database connection if SKIP_RAISE_ON_INITIALIZE_CONNECTIONS is false' do
stub_env('SKIP_RAISE_ON_INITIALIZE_CONNECTIONS', 'false')
expect { block_with_database_call }.to raise_error(/Database connection should not be called during initializer/)
end
it 'restores original connection handler', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/444963' do
it 'restores original connection handler' do
original_handler = ActiveRecord::Base.connection_handler
expect { block_with_database_call }.to raise_error(/Database connection should not be called during initializer/)
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe 'gitlab:backup namespace rake tasks', :delete, feature_category: :backup_restore do
RSpec.describe 'gitlab:backup namespace rake tasks', :reestablished_active_record_base, :delete, feature_category: :backup_restore do
let(:enable_registry) { true }
let(:backup_restore_pid_path) { "#{Rails.application.root}/tmp/backup_restore.pid" }
let(:backup_rake_task_names) do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment