diff options
Diffstat (limited to 'spec/lib/gitlab/checks/matching_merge_request_spec.rb')
-rw-r--r-- | spec/lib/gitlab/checks/matching_merge_request_spec.rb | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/spec/lib/gitlab/checks/matching_merge_request_spec.rb b/spec/lib/gitlab/checks/matching_merge_request_spec.rb index 2e562a5a350..c65a1e4d656 100644 --- a/spec/lib/gitlab/checks/matching_merge_request_spec.rb +++ b/spec/lib/gitlab/checks/matching_merge_request_spec.rb @@ -31,33 +31,30 @@ RSpec.describe Gitlab::Checks::MatchingMergeRequest do expect(matcher.match?).to be false end - context 'with load balancing disabled', :request_store, :redis do - before do - expect(::Gitlab::Database::LoadBalancing).to receive(:enable?).at_least(:once).and_return(false) - expect(::Gitlab::Database::LoadBalancing::Sticking).not_to receive(:unstick_or_continue_sticking) - expect(::Gitlab::Database::LoadBalancing::Sticking).not_to receive(:select_valid_replicas) - end - - it 'does not attempt to stick to primary' do - expect(subject.match?).to be true - end - - it 'increments no counters' do - expect { subject.match? } - .to change { total_counter.get }.by(0) - .and change { stale_counter.get }.by(0) - end - end - - context 'with load balancing enabled', :db_load_balancing do + context 'with load balancing enabled' do let(:session) { ::Gitlab::Database::LoadBalancing::Session.current } let(:all_caught_up) { true } before do - allow(::Gitlab::Database::LoadBalancing::Sticking).to receive(:all_caught_up?).and_return(all_caught_up) + Gitlab::Database::LoadBalancing::Session.clear_session + + allow(::ApplicationRecord.sticking) + .to receive(:all_caught_up?) + .and_return(all_caught_up) + + expect(::ApplicationRecord.sticking) + .to receive(:select_valid_host) + .with(:project, project.id) + .and_call_original + + allow(::ApplicationRecord.sticking) + .to receive(:select_caught_up_replicas) + .with(:project, project.id) + .and_return(all_caught_up) + end - expect(::Gitlab::Database::LoadBalancing::Sticking).to receive(:select_valid_host).with(:project, project.id).and_call_original - allow(::Gitlab::Database::LoadBalancing::Sticking).to receive(:select_caught_up_replicas).with(:project, project.id).and_return(all_caught_up) + after do + Gitlab::Database::LoadBalancing::Session.clear_session end shared_examples 'secondary that has caught up to a primary' do |