Commit d10642a4 authored by Stan Hu's avatar Stan Hu

Handle case when Redis cache returns an empty setting

parent c600cf83
......@@ -11,7 +11,7 @@ module Gitlab
def ensure_application_settings!
if connect_to_db?
begin
settings = ::ApplicationSetting.cached
settings = ::ApplicationSetting.current
# In case Redis isn't running or the Redis UNIX socket file is not available
rescue ::Redis::BaseError, ::Errno::ENOENT
settings = ::ApplicationSetting.last
......
......@@ -4,7 +4,7 @@ describe Gitlab::CurrentSettings do
describe '#current_application_settings' do
it 'attempts to use cached values first' do
allow_any_instance_of(Gitlab::CurrentSettings).to receive(:connect_to_db?).and_return(true)
expect(ApplicationSetting).to receive(:cached).and_call_original
expect(ApplicationSetting).to receive(:current).and_return(::ApplicationSetting.create_from_defaults)
expect(ApplicationSetting).not_to receive(:last)
expect(current_application_settings).to be_a(ApplicationSetting)
......@@ -18,9 +18,16 @@ describe Gitlab::CurrentSettings do
expect(current_application_settings).to eq fake_application_settings
end
it 'falls back to DB if Redis returns an empty value' do
allow_any_instance_of(Gitlab::CurrentSettings).to receive(:connect_to_db?).and_return(true)
expect(ApplicationSetting).to receive(:last).and_call_original
expect(current_application_settings).to be_a(ApplicationSetting)
end
it 'falls back to DB if Redis fails' do
allow_any_instance_of(Gitlab::CurrentSettings).to receive(:connect_to_db?).and_return(true)
expect(ApplicationSetting).to receive(:cached).and_raise(::Redis::BaseError)
expect(ApplicationSetting).to receive(:current).and_raise(::Redis::BaseError)
expect(ApplicationSetting).to receive(:last).and_call_original
expect(current_application_settings).to be_a(ApplicationSetting)
......
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