2021-08-05 14:10:13 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
2021-10-11 11:13:01 -04:00
|
|
|
config.around(:each, :database_replica) do |example|
|
2021-11-09 01:13:00 -05:00
|
|
|
old_proxies = {}
|
2021-08-05 14:10:13 -04:00
|
|
|
|
2021-10-11 11:13:01 -04:00
|
|
|
Gitlab::Database::LoadBalancing.base_models.each do |model|
|
2021-11-09 01:13:00 -05:00
|
|
|
old_proxies[model] = [model.load_balancer, model.connection, model.sticking]
|
|
|
|
|
2021-10-11 11:13:01 -04:00
|
|
|
config = Gitlab::Database::LoadBalancing::Configuration
|
|
|
|
.new(model, [model.connection_db_config.configuration_hash[:host]])
|
|
|
|
|
2021-11-09 01:13:00 -05:00
|
|
|
model.load_balancer = Gitlab::Database::LoadBalancing::LoadBalancer.new(config)
|
|
|
|
model.sticking = Gitlab::Database::LoadBalancing::Sticking.new(model.load_balancer)
|
|
|
|
model.connection = Gitlab::Database::LoadBalancing::ConnectionProxy.new(model.load_balancer)
|
2021-10-11 11:13:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
Gitlab::Database::LoadBalancing::Session.clear_session
|
2021-08-05 14:10:13 -04:00
|
|
|
redis_shared_state_cleanup!
|
|
|
|
|
2021-10-11 11:13:01 -04:00
|
|
|
example.run
|
|
|
|
|
|
|
|
Gitlab::Database::LoadBalancing::Session.clear_session
|
2021-08-05 14:10:13 -04:00
|
|
|
redis_shared_state_cleanup!
|
2021-10-11 11:13:01 -04:00
|
|
|
|
2021-11-09 01:13:00 -05:00
|
|
|
old_proxies.each do |model, proxy|
|
|
|
|
model.load_balancer, model.connection, model.sticking = proxy
|
2021-10-11 11:13:01 -04:00
|
|
|
end
|
2021-08-05 14:10:13 -04:00
|
|
|
end
|
|
|
|
end
|