Commit a54f8b68 authored by Nikola Milojevic's avatar Nikola Milojevic Committed by Kamil Trzciński

SidekiqClientMiddleware should continue using primary if primary was already selected

parent cd011d38
......@@ -26,7 +26,7 @@ module Gitlab
return if worker_class.get_data_consistency == :always
if Session.current.performed_write?
if Session.current.use_primary?
job['database_write_location'] = load_balancer.primary_write_location
else
job['database_replica_location'] = load_balancer.host.database_replica_location
......
......@@ -55,7 +55,7 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqClientMiddleware do
context 'when write was not performed' do
before do
allow(Gitlab::Database::LoadBalancing::Session.current).to receive(:performed_write?).and_return(false)
allow(Gitlab::Database::LoadBalancing::Session.current).to receive(:use_primary?).and_return(false)
end
it 'passes database_replica_location' do
......@@ -69,7 +69,7 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqClientMiddleware do
context 'when write was performed' do
before do
allow(Gitlab::Database::LoadBalancing::Session.current).to receive(:performed_write?).and_return(true)
allow(Gitlab::Database::LoadBalancing::Session.current).to receive(:use_primary?).and_return(true)
end
it 'passes primary write location', :aggregate_failures do
......@@ -83,9 +83,9 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqClientMiddleware do
end
shared_examples_for 'database location was already provided' do |provided_database_location, other_location|
shared_examples_for 'does not set database location again' do |write_performed|
shared_examples_for 'does not set database location again' do |use_primary|
before do
allow(Gitlab::Database::LoadBalancing::Session.current).to receive(:performed_write?).and_return(write_performed)
allow(Gitlab::Database::LoadBalancing::Session.current).to receive(:use_primary?).and_return(use_primary)
end
it 'does not set database locations again' do
......
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