Welcome to mirror list, hosted at ThFree Co, Russian Federation.

primary_host_spec.rb « load_balancing « database « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 02c9499bedbc92451770ae83630c3460d10c208e (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Database::LoadBalancing::PrimaryHost do
  let(:load_balancer) do
    Gitlab::Database::LoadBalancing::LoadBalancer.new(
      Gitlab::Database::LoadBalancing::Configuration.new(ActiveRecord::Base)
    )
  end

  let(:host) { Gitlab::Database::LoadBalancing::PrimaryHost.new(load_balancer) }

  describe '#connection' do
    it 'returns a connection from the pool' do
      expect(load_balancer.pool).to receive(:connection)

      host.connection
    end
  end

  describe '#release_connection' do
    it 'does nothing' do
      expect(host.release_connection).to be_nil
    end
  end

  describe '#enable_query_cache!' do
    it 'does nothing' do
      expect(host.enable_query_cache!).to be_nil
    end
  end

  describe '#disable_query_cache!' do
    it 'does nothing' do
      expect(host.disable_query_cache!).to be_nil
    end
  end

  describe '#query_cache_enabled' do
    it 'delegates to the primary connection pool' do
      expect(host.query_cache_enabled)
        .to eq(load_balancer.pool.query_cache_enabled)
    end
  end

  describe '#disconnect!' do
    it 'does nothing' do
      expect(host.disconnect!).to be_nil
    end
  end

  describe '#offline!' do
    it 'logs the event but does nothing else' do
      expect(Gitlab::Database::LoadBalancing::Logger).to receive(:warn)
        .with(hash_including(event: :host_offline))
        .and_call_original

      expect(host.offline!).to be_nil
    end
  end

  describe '#online?' do
    it 'returns true' do
      expect(host.online?).to eq(true)
    end
  end

  describe '#primary_write_location' do
    it 'raises NotImplementedError' do
      expect { host.primary_write_location }.to raise_error(NotImplementedError)
    end
  end

  describe '#caught_up?' do
    it 'returns true' do
      expect(host.caught_up?('foo')).to eq(true)
    end
  end

  describe '#database_replica_location' do
    it 'raises NotImplementedError' do
      expect { host.database_replica_location }.to raise_error(NotImplementedError)
    end
  end
end