diff options
Diffstat (limited to 'spec/lib/gitlab/redis')
-rw-r--r-- | spec/lib/gitlab/redis/cache_spec.rb | 22 | ||||
-rw-r--r-- | spec/lib/gitlab/redis/queues_spec.rb | 22 | ||||
-rw-r--r-- | spec/lib/gitlab/redis/shared_state_spec.rb | 22 | ||||
-rw-r--r-- | spec/lib/gitlab/redis/trace_chunks_spec.rb | 55 | ||||
-rw-r--r-- | spec/lib/gitlab/redis/wrapper_spec.rb | 42 |
5 files changed, 84 insertions, 79 deletions
diff --git a/spec/lib/gitlab/redis/cache_spec.rb b/spec/lib/gitlab/redis/cache_spec.rb index 5f73b84288d..31141ac1139 100644 --- a/spec/lib/gitlab/redis/cache_spec.rb +++ b/spec/lib/gitlab/redis/cache_spec.rb @@ -3,20 +3,16 @@ require 'spec_helper' RSpec.describe Gitlab::Redis::Cache do - let(:config_file_name) { "config/redis.cache.yml" } + let(:instance_specific_config_file) { "config/redis.cache.yml" } let(:environment_config_file_name) { "GITLAB_REDIS_CACHE_CONFIG_FILE" } - let(:config_old_format_socket) { "spec/fixtures/config/redis_cache_old_format_socket.yml" } - let(:config_new_format_socket) { "spec/fixtures/config/redis_cache_new_format_socket.yml" } - let(:old_socket_path) {"/path/to/old/redis.cache.sock" } - let(:new_socket_path) {"/path/to/redis.cache.sock" } - let(:config_old_format_host) { "spec/fixtures/config/redis_cache_old_format_host.yml" } - let(:config_new_format_host) { "spec/fixtures/config/redis_cache_new_format_host.yml" } - let(:redis_port) { 6380 } - let(:redis_database) { 10 } - let(:sentinel_port) { redis_port + 20000 } - let(:config_with_environment_variable_inside) { "spec/fixtures/config/redis_cache_config_with_env.yml"} - let(:config_env_variable_url) {"TEST_GITLAB_REDIS_CACHE_URL"} - let(:class_redis_url) { Gitlab::Redis::Cache::DEFAULT_REDIS_CACHE_URL } include_examples "redis_shared_examples" + + describe '#raw_config_hash' do + it 'has a legacy default URL' do + expect(subject).to receive(:fetch_config) { false } + + expect(subject.send(:raw_config_hash)).to eq(url: 'redis://localhost:6380' ) + end + end end diff --git a/spec/lib/gitlab/redis/queues_spec.rb b/spec/lib/gitlab/redis/queues_spec.rb index 8a32c991943..2e396cde3bf 100644 --- a/spec/lib/gitlab/redis/queues_spec.rb +++ b/spec/lib/gitlab/redis/queues_spec.rb @@ -3,20 +3,16 @@ require 'spec_helper' RSpec.describe Gitlab::Redis::Queues do - let(:config_file_name) { "config/redis.queues.yml" } + let(:instance_specific_config_file) { "config/redis.queues.yml" } let(:environment_config_file_name) { "GITLAB_REDIS_QUEUES_CONFIG_FILE" } - let(:config_old_format_socket) { "spec/fixtures/config/redis_queues_old_format_socket.yml" } - let(:config_new_format_socket) { "spec/fixtures/config/redis_queues_new_format_socket.yml" } - let(:old_socket_path) {"/path/to/old/redis.queues.sock" } - let(:new_socket_path) {"/path/to/redis.queues.sock" } - let(:config_old_format_host) { "spec/fixtures/config/redis_queues_old_format_host.yml" } - let(:config_new_format_host) { "spec/fixtures/config/redis_queues_new_format_host.yml" } - let(:redis_port) { 6381 } - let(:redis_database) { 11 } - let(:sentinel_port) { redis_port + 20000 } - let(:config_with_environment_variable_inside) { "spec/fixtures/config/redis_queues_config_with_env.yml"} - let(:config_env_variable_url) {"TEST_GITLAB_REDIS_QUEUES_URL"} - let(:class_redis_url) { Gitlab::Redis::Queues::DEFAULT_REDIS_QUEUES_URL } include_examples "redis_shared_examples" + + describe '#raw_config_hash' do + it 'has a legacy default URL' do + expect(subject).to receive(:fetch_config) { false } + + expect(subject.send(:raw_config_hash)).to eq(url: 'redis://localhost:6381' ) + end + end end diff --git a/spec/lib/gitlab/redis/shared_state_spec.rb b/spec/lib/gitlab/redis/shared_state_spec.rb index bd90e4c750d..d240abfbf5b 100644 --- a/spec/lib/gitlab/redis/shared_state_spec.rb +++ b/spec/lib/gitlab/redis/shared_state_spec.rb @@ -3,20 +3,16 @@ require 'spec_helper' RSpec.describe Gitlab::Redis::SharedState do - let(:config_file_name) { "config/redis.shared_state.yml" } + let(:instance_specific_config_file) { "config/redis.shared_state.yml" } let(:environment_config_file_name) { "GITLAB_REDIS_SHARED_STATE_CONFIG_FILE" } - let(:config_old_format_socket) { "spec/fixtures/config/redis_shared_state_old_format_socket.yml" } - let(:config_new_format_socket) { "spec/fixtures/config/redis_shared_state_new_format_socket.yml" } - let(:old_socket_path) {"/path/to/old/redis.shared_state.sock" } - let(:new_socket_path) {"/path/to/redis.shared_state.sock" } - let(:config_old_format_host) { "spec/fixtures/config/redis_shared_state_old_format_host.yml" } - let(:config_new_format_host) { "spec/fixtures/config/redis_shared_state_new_format_host.yml" } - let(:redis_port) { 6382 } - let(:redis_database) { 12 } - let(:sentinel_port) { redis_port + 20000 } - let(:config_with_environment_variable_inside) { "spec/fixtures/config/redis_shared_state_config_with_env.yml"} - let(:config_env_variable_url) {"TEST_GITLAB_REDIS_SHARED_STATE_URL"} - let(:class_redis_url) { Gitlab::Redis::SharedState::DEFAULT_REDIS_SHARED_STATE_URL } include_examples "redis_shared_examples" + + describe '#raw_config_hash' do + it 'has a legacy default URL' do + expect(subject).to receive(:fetch_config) { false } + + expect(subject.send(:raw_config_hash)).to eq(url: 'redis://localhost:6382' ) + end + end end diff --git a/spec/lib/gitlab/redis/trace_chunks_spec.rb b/spec/lib/gitlab/redis/trace_chunks_spec.rb new file mode 100644 index 00000000000..e974dc519d6 --- /dev/null +++ b/spec/lib/gitlab/redis/trace_chunks_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Redis::TraceChunks do + let(:instance_specific_config_file) { "config/redis.trace_chunks.yml" } + let(:environment_config_file_name) { "GITLAB_REDIS_TRACE_CHUNKS_CONFIG_FILE" } + let(:shared_state_config_file) { nil } + + before do + allow(Gitlab::Redis::SharedState).to receive(:config_file_name).and_return(shared_state_config_file) + end + + include_examples "redis_shared_examples" + + describe '.config_file_name' do + subject { described_class.config_file_name } + + let(:rails_root) { Dir.mktmpdir('redis_shared_examples') } + + 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) + FileUtils.mkdir_p(File.join(rails_root, 'config')) + end + + after do + FileUtils.rm_rf(rails_root) + end + + context 'when there is only a resque.yml' do + before do + FileUtils.touch(File.join(rails_root, 'config/resque.yml')) + end + + it { expect(subject).to eq("#{rails_root}/config/resque.yml") } + + context 'and there is a global env override' do + before do + stub_env('GITLAB_REDIS_CONFIG_FILE', 'global override') + end + + it { expect(subject).to eq('global override') } + + context 'and SharedState has a different config file' do + let(:shared_state_config_file) { 'shared state config file' } + + it { expect(subject).to eq('shared state config file') } + end + end + end + end +end diff --git a/spec/lib/gitlab/redis/wrapper_spec.rb b/spec/lib/gitlab/redis/wrapper_spec.rb index ec233c022ee..dd1f0d8b414 100644 --- a/spec/lib/gitlab/redis/wrapper_spec.rb +++ b/spec/lib/gitlab/redis/wrapper_spec.rb @@ -3,47 +3,9 @@ require 'spec_helper' RSpec.describe Gitlab::Redis::Wrapper do - let(:config_file_name) { "config/resque.yml" } - let(:environment_config_file_name) { "GITLAB_REDIS_CONFIG_FILE" } - let(:config_old_format_socket) { "spec/fixtures/config/redis_old_format_socket.yml" } - let(:config_new_format_socket) { "spec/fixtures/config/redis_new_format_socket.yml" } - let(:old_socket_path) {"/path/to/old/redis.sock" } - let(:new_socket_path) {"/path/to/redis.sock" } - let(:config_old_format_host) { "spec/fixtures/config/redis_old_format_host.yml" } - let(:config_new_format_host) { "spec/fixtures/config/redis_new_format_host.yml" } - let(:redis_port) { 6379 } - let(:redis_database) { 99 } - let(:sentinel_port) { redis_port + 20000 } - let(:config_with_environment_variable_inside) { "spec/fixtures/config/redis_config_with_env.yml"} - let(:config_env_variable_url) {"TEST_GITLAB_REDIS_URL"} - let(:class_redis_url) { Gitlab::Redis::Wrapper::DEFAULT_REDIS_URL } - - include_examples "redis_shared_examples" do - before do - allow(described_class).to receive(:instrumentation_class) do - ::Gitlab::Instrumentation::Redis::Cache - end - end - end - - describe '.version' do - it 'returns a version' do - expect(described_class.version).to be_present - end - end - describe '.instrumentation_class' do - it 'raises a NotImplementedError' do - expect(described_class).to receive(:instrumentation_class).and_call_original - - expect { described_class.instrumentation_class }.to raise_error(NotImplementedError) - end - end - - describe '.config_file_path' do - it 'returns the absolute path to the configuration file' do - expect(described_class.config_file_path('foo.yml')) - .to eq Rails.root.join('config', 'foo.yml').to_s + it 'raises a NameError' do + expect { described_class.instrumentation_class }.to raise_error(NameError) end end end |