blob: 3993004518d67b0ba36504d1674134d0837afd23 (
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
|
# 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_store = pri_store == :cluster ? ::Redis.new(cluster: ['redis://localhost:6000']) : ::Redis.new
secondary_store = sec_store == :cluster ? ::Redis.new(cluster: ['redis://localhost:6000']) : ::Redis.new
multistore = Gitlab::Redis::MultiStore.new(primary_store, secondary_store, 'teststore')
expect(described_class.cluster?(multistore)).to eq(expected_val)
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
|