debian-mirror-gitlab/spec/support/database_load_balancing.rb

31 lines
1 KiB
Ruby
Raw Normal View History

2021-10-27 15:23:28 +05:30
# frozen_string_literal: true
RSpec.configure do |config|
2021-11-18 22:05:49 +05:30
config.around(:each, :database_replica) do |example|
2021-12-11 22:18:48 +05:30
old_proxies = {}
2021-10-27 15:23:28 +05:30
2021-11-18 22:05:49 +05:30
Gitlab::Database::LoadBalancing.base_models.each do |model|
2021-12-11 22:18:48 +05:30
old_proxies[model] = [model.load_balancer, model.connection, model.sticking]
2021-11-18 22:05:49 +05:30
config = Gitlab::Database::LoadBalancing::Configuration
.new(model, [model.connection_db_config.configuration_hash[:host]])
2021-10-27 15:23:28 +05:30
2021-12-11 22:18:48 +05:30
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-11-18 22:05:49 +05:30
end
Gitlab::Database::LoadBalancing::Session.clear_session
2021-10-27 15:23:28 +05:30
redis_shared_state_cleanup!
2021-11-18 22:05:49 +05:30
example.run
Gitlab::Database::LoadBalancing::Session.clear_session
2021-10-27 15:23:28 +05:30
redis_shared_state_cleanup!
2021-11-18 22:05:49 +05:30
2021-12-11 22:18:48 +05:30
old_proxies.each do |model, proxy|
model.load_balancer, model.connection, model.sticking = proxy
2021-11-18 22:05:49 +05:30
end
2021-10-27 15:23:28 +05:30
end
end