Commit 7e79dc31 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Redis: always return config hash

This is to prevent issues like
https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/6177.
parent dd39fe1a
...@@ -8,7 +8,9 @@ module Gitlab ...@@ -8,7 +8,9 @@ module Gitlab
private private
def raw_config_hash def raw_config_hash
super || { url: 'redis://localhost:6380' } config = super
config[:url] = 'redis://localhost:6380' if config[:url].blank?
config
end end
end end
end end
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# We need this require for MailRoom # We need this require for MailRoom
require_relative 'wrapper' unless defined?(::Gitlab::Redis::Wrapper) require_relative 'wrapper' unless defined?(::Gitlab::Redis::Wrapper)
require 'active_support/core_ext/object/blank'
module Gitlab module Gitlab
module Redis module Redis
...@@ -12,7 +13,9 @@ module Gitlab ...@@ -12,7 +13,9 @@ module Gitlab
private private
def raw_config_hash def raw_config_hash
super || { url: 'redis://localhost:6381' } config = super
config[:url] = 'redis://localhost:6381' if config[:url].blank?
config
end end
end end
end end
......
...@@ -11,7 +11,9 @@ module Gitlab ...@@ -11,7 +11,9 @@ module Gitlab
private private
def raw_config_hash def raw_config_hash
super || { url: 'redis://localhost:6382' } config = super
config[:url] = 'redis://localhost:6382' if config[:url].blank?
config
end end
end end
end end
......
...@@ -133,6 +133,8 @@ module Gitlab ...@@ -133,6 +133,8 @@ module Gitlab
if config_data if config_data
config_data.is_a?(String) ? { url: config_data } : config_data.deep_symbolize_keys config_data.is_a?(String) ? { url: config_data } : config_data.deep_symbolize_keys
else
{ url: '' }
end end
end end
......
...@@ -16,6 +16,7 @@ RSpec.shared_examples "redis_shared_examples" do ...@@ -16,6 +16,7 @@ RSpec.shared_examples "redis_shared_examples" do
let(:sentinel_port) { 26379 } let(:sentinel_port) { 26379 }
let(:config_with_environment_variable_inside) { "spec/fixtures/config/redis_config_with_env.yml"} let(:config_with_environment_variable_inside) { "spec/fixtures/config/redis_config_with_env.yml"}
let(:config_env_variable_url) {"TEST_GITLAB_REDIS_URL"} let(:config_env_variable_url) {"TEST_GITLAB_REDIS_URL"}
let(:rails_root) { Dir.mktmpdir('redis_shared_examples') }
before do before do
allow(described_class).to receive(:config_file_name).and_return(Rails.root.join(config_file_name).to_s) allow(described_class).to receive(:config_file_name).and_return(Rails.root.join(config_file_name).to_s)
...@@ -29,8 +30,6 @@ RSpec.shared_examples "redis_shared_examples" do ...@@ -29,8 +30,6 @@ RSpec.shared_examples "redis_shared_examples" do
describe '.config_file_name' do describe '.config_file_name' do
subject { described_class.config_file_name } subject { described_class.config_file_name }
let(:rails_root) { Dir.mktmpdir('redis_shared_examples') }
before do before do
# Undo top-level stub of config_file_name because we are testing that method now. # Undo top-level stub of config_file_name because we are testing that method now.
allow(described_class).to receive(:config_file_name).and_call_original allow(described_class).to receive(:config_file_name).and_call_original
...@@ -237,6 +236,23 @@ RSpec.shared_examples "redis_shared_examples" do ...@@ -237,6 +236,23 @@ RSpec.shared_examples "redis_shared_examples" do
described_class.with { |_redis_shared_example| true } described_class.with { |_redis_shared_example| true }
end end
end end
context 'when there is no config at all' do
before do
# Undo top-level stub of config_file_name because we are testing that method now.
allow(described_class).to receive(:config_file_name).and_call_original
allow(described_class).to receive(:rails_root).and_return(rails_root)
end
after do
FileUtils.rm_rf(rails_root)
end
it 'can run an empty block' do
expect { described_class.with { nil } }.not_to raise_error
end
end
end end
describe '#sentinels' do describe '#sentinels' do
......
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