blob: f167065fd3f74b4f6a628e3b550701a6d00596e4 (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Redis::ClusterUtil, feature_category: :scalability do
using RSpec::Parameterized::TableSyntax
describe '.cluster?' do
context 'when MultiStore' do
let(:redis_cluster) { instance_double(::Redis::Cluster) }
where(:pri_store, :sec_store, :expected_val) do
:cluster | :cluster | true
:cluster | :single | true
:single | :cluster | true
:single | :single | false
end
before do
# stub all initialiser steps in Redis::Cluster.new to avoid connecting to a Redis Cluster node
allow(::Redis::Cluster).to receive(:new).and_return(redis_cluster)
allow(redis_cluster).to receive(:is_a?).with(::Redis::Cluster).and_return(true)
allow(redis_cluster).to receive(:id).and_return(1)
allow(Gitlab::Redis::MultiStore).to receive(:same_redis_store?).and_return(false)
skip_feature_flags_yaml_validation
skip_default_enabled_yaml_check
end
with_them do
it 'returns expected value' do
primary_redis = pri_store == :cluster ? ::Redis.new(cluster: ['redis://localhost:6000']) : ::Redis.new
secondary_redis = sec_store == :cluster ? ::Redis.new(cluster: ['redis://localhost:6000']) : ::Redis.new
primary_pool = ConnectionPool.new { primary_redis }
secondary_pool = ConnectionPool.new { secondary_redis }
multistore = Gitlab::Redis::MultiStore.new(primary_pool, secondary_pool, 'teststore')
multistore.with_borrowed_connection do
expect(described_class.cluster?(multistore)).to eq(expected_val)
end
end
end
end
context 'when is not Redis::Cluster' do
it 'returns false' do
expect(described_class.cluster?(::Redis.new)).to be_falsey
end
end
context 'when is Redis::Cluster' do
let(:redis_cluster) { instance_double(::Redis::Cluster) }
before do
# stub all initialiser steps in Redis::Cluster.new to avoid connecting to a Redis Cluster node
allow(::Redis::Cluster).to receive(:new).and_return(redis_cluster)
allow(redis_cluster).to receive(:is_a?).with(::Redis::Cluster).and_return(true)
end
it 'returns true' do
expect(described_class.cluster?(::Redis.new(cluster: ['redis://localhost:6000']))).to be_truthy
end
end
end
end
|