summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/database/load_balancing/action_cable_callbacks_spec.rb
blob: ebbbafb855ffa14c0a22dde0ef541a301611c1f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Database::LoadBalancing::ActionCableCallbacks, :request_store do
  describe '.wrapper' do
    it 'uses primary and then releases the connection and clears the session' do
      expect(Gitlab::Database::LoadBalancing).to receive_message_chain(:proxy, :load_balancer, :release_host)
      expect(Gitlab::Database::LoadBalancing::Session).to receive(:clear_session)

      described_class.wrapper.call(
        nil,
        lambda do
          expect(Gitlab::Database::LoadBalancing::Session.current.use_primary?).to eq(true)
        end
      )
    end

    context 'with an exception' do
      it 'releases the connection and clears the session' do
        expect(Gitlab::Database::LoadBalancing).to receive_message_chain(:proxy, :load_balancer, :release_host)
        expect(Gitlab::Database::LoadBalancing::Session).to receive(:clear_session)

        expect do
          described_class.wrapper.call(nil, lambda { raise 'test_exception' })
        end.to raise_error('test_exception')
      end
    end
  end
end