Commit 581c7c49 authored by nmilojevic1's avatar nmilojevic1

Add validation for primary and secondary stores

parent 7b4de75b
...@@ -40,12 +40,11 @@ module Gitlab ...@@ -40,12 +40,11 @@ module Gitlab
).freeze ).freeze
def initialize(primary_store, secondary_store, instance_name = nil) def initialize(primary_store, secondary_store, instance_name = nil)
raise ArgumentError, 'primary_store is required' unless primary_store
raise ArgumentError, 'secondary_store is required' unless secondary_store
@primary_store = primary_store @primary_store = primary_store
@secondary_store = secondary_store @secondary_store = secondary_store
@instance_name = instance_name @instance_name = instance_name
validate_stores!
end end
READ_COMMANDS.each do |name| READ_COMMANDS.each do |name|
...@@ -198,6 +197,13 @@ module Gitlab ...@@ -198,6 +197,13 @@ module Gitlab
@method_missing_counter.increment(command: command_name, innamece_name: instance_name) @method_missing_counter.increment(command: command_name, innamece_name: instance_name)
end end
def validate_stores!
raise ArgumentError, 'primary_store is required' unless primary_store
raise ArgumentError, 'secondary_store is required' unless secondary_store
raise ArgumentError, 'invalid primary_store' unless primary_store.is_a?(::Redis)
raise ArgumentError, 'invalid secondary_store' unless secondary_store.is_a?(::Redis)
end
def log_error(exception, command_name, extra = {}) def log_error(exception, command_name, extra = {})
Gitlab::ErrorTracking.log_exception( Gitlab::ErrorTracking.log_exception(
exception, exception,
......
...@@ -48,6 +48,26 @@ RSpec.describe Gitlab::Redis::MultiStore do ...@@ -48,6 +48,26 @@ RSpec.describe Gitlab::Redis::MultiStore do
end end
end end
context 'when primary_store is not a ::Redis instance' do
before do
allow(primary_store).to receive(:is_a?).with(::Redis).and_return(false)
end
it 'fails with exception' do
expect { described_class.new(primary_store, secondary_store, instance_name) }.to raise_error(ArgumentError, /invalid primary_store/)
end
end
context 'when secondary_store is not a ::Redis instance' do
before do
allow(secondary_store).to receive(:is_a?).with(::Redis).and_return(false)
end
it 'fails with exception' do
expect { described_class.new(primary_store, secondary_store, instance_name) }.to raise_error(ArgumentError, /invalid secondary_store/)
end
end
context 'with READ redis commands' do context 'with READ redis commands' do
let_it_be(:key1) { "redis:{1}:key_a" } let_it_be(:key1) { "redis:{1}:key_a" }
let_it_be(:key2) { "redis:{1}:key_b" } let_it_be(:key2) { "redis:{1}:key_b" }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment