From aee0a117a889461ce8ced6fcf73207fe017f1d99 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 20 Dec 2021 13:37:47 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-6-stable-ee --- spec/support/redis/redis_helpers.rb | 7 +++++++ .../redis/redis_new_instance_shared_examples.rb | 8 +++++++- spec/support/redis/redis_shared_examples.rb | 21 ++++++++++----------- 3 files changed, 24 insertions(+), 12 deletions(-) (limited to 'spec/support/redis') diff --git a/spec/support/redis/redis_helpers.rb b/spec/support/redis/redis_helpers.rb index f27d873eb31..90c15dea1f8 100644 --- a/spec/support/redis/redis_helpers.rb +++ b/spec/support/redis/redis_helpers.rb @@ -32,4 +32,11 @@ module RedisHelpers def redis_sessions_cleanup! Gitlab::Redis::Sessions.with(&:flushdb) end + + # Usage: reset cached instance config + def redis_clear_raw_config!(instance_class) + instance_class.remove_instance_variable(:@_raw_config) + rescue NameError + # raised if @_raw_config was not set; ignore + end end diff --git a/spec/support/redis/redis_new_instance_shared_examples.rb b/spec/support/redis/redis_new_instance_shared_examples.rb index e9b1e3e4da1..943fe0f11ba 100644 --- a/spec/support/redis/redis_new_instance_shared_examples.rb +++ b/spec/support/redis/redis_new_instance_shared_examples.rb @@ -8,10 +8,16 @@ RSpec.shared_examples "redis_new_instance_shared_examples" do |name, fallback_cl let(:fallback_config_file) { nil } before do + redis_clear_raw_config!(fallback_class) + allow(fallback_class).to receive(:config_file_name).and_return(fallback_config_file) end - include_examples "redis_shared_examples" + after do + redis_clear_raw_config!(fallback_class) + end + + it_behaves_like "redis_shared_examples" describe '.config_file_name' do subject { described_class.config_file_name } diff --git a/spec/support/redis/redis_shared_examples.rb b/spec/support/redis/redis_shared_examples.rb index 72b3a72f9d4..d4c8682ec71 100644 --- a/spec/support/redis/redis_shared_examples.rb +++ b/spec/support/redis/redis_shared_examples.rb @@ -20,11 +20,11 @@ RSpec.shared_examples "redis_shared_examples" do before do allow(described_class).to receive(:config_file_name).and_return(Rails.root.join(config_file_name).to_s) - clear_raw_config + redis_clear_raw_config!(described_class) end after do - clear_raw_config + redis_clear_raw_config!(described_class) end describe '.config_file_name' do @@ -93,18 +93,23 @@ RSpec.shared_examples "redis_shared_examples" do subject { described_class.new(rails_env).store } shared_examples 'redis store' do + let(:redis_store) { ::Redis::Store } + let(:redis_store_to_s) { "Redis Client connected to #{host} against DB #{redis_database}" } + it 'instantiates Redis::Store' do - is_expected.to be_a(::Redis::Store) - expect(subject.to_s).to eq("Redis Client connected to #{host} against DB #{redis_database}") + is_expected.to be_a(redis_store) + + expect(subject.to_s).to eq(redis_store_to_s) end context 'with the namespace' do let(:namespace) { 'namespace_name' } + let(:redis_store_to_s) { "Redis Client connected to #{host} against DB #{redis_database} with namespace #{namespace}" } subject { described_class.new(rails_env).store(namespace: namespace) } it "uses specified namespace" do - expect(subject.to_s).to eq("Redis Client connected to #{host} against DB #{redis_database} with namespace #{namespace}") + expect(subject.to_s).to eq(redis_store_to_s) end end end @@ -394,12 +399,6 @@ RSpec.shared_examples "redis_shared_examples" do end end - def clear_raw_config - described_class.remove_instance_variable(:@_raw_config) - rescue NameError - # raised if @_raw_config was not set; ignore - end - def clear_pool described_class.remove_instance_variable(:@pool) rescue NameError -- cgit v1.2.3