diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-19 21:07:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-19 21:07:19 +0300 |
commit | 2f00709f337c76982dfe69cbc62dc3cb148131f2 (patch) | |
tree | 0cc6ceef69f03d9fcc2bc0e27ce4341b40a0773e /spec | |
parent | 8bb837c4d180720d4d923ef2e7bd2c9a46ca97a0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
3 files changed, 55 insertions, 24 deletions
diff --git a/spec/lib/gitlab/redis/multi_store_spec.rb b/spec/lib/gitlab/redis/multi_store_spec.rb index 80d5915b819..05cc1569a40 100644 --- a/spec/lib/gitlab/redis/multi_store_spec.rb +++ b/spec/lib/gitlab/redis/multi_store_spec.rb @@ -269,8 +269,8 @@ RSpec.describe Gitlab::Redis::MultiStore, feature_category: :redis do multi_store.default_store.flushdb end - it 'does not call the fallback store' do - expect(multi_store.fallback_store).not_to receive(name) + it 'does not call the non_default_store' do + expect(multi_store.non_default_store).not_to receive(name) end end @@ -574,21 +574,33 @@ RSpec.describe Gitlab::Redis::MultiStore, feature_category: :redis do end end - context 'when executing on the primary instance is raising an exception' do + context 'when executing on the default instance is raising an exception' do before do - allow(primary_store).to receive(name).with(*expected_args).and_raise(StandardError) + allow(multi_store.default_store).to receive(name).with(*expected_args).and_raise(StandardError) allow(Gitlab::ErrorTracking).to receive(:log_exception) end - it 'logs the exception and execute on secondary instance', :aggregate_failures do + it 'raises error and does not execute on non default instance', :aggregate_failures do + expect(multi_store.non_default_store).not_to receive(name).with(*expected_args) + expect { subject }.to raise_error(StandardError) + end + end + + context 'when executing on the non default instance is raising an exception' do + before do + allow(multi_store.non_default_store).to receive(name).with(*expected_args).and_raise(StandardError) + allow(Gitlab::ErrorTracking).to receive(:log_exception) + end + + it 'logs the exception and execute on default instance', :aggregate_failures do expect(Gitlab::ErrorTracking).to receive(:log_exception).with(an_instance_of(StandardError), hash_including(:multi_store_error_message, command_name: name, instance_name: instance_name)) - expect(secondary_store).to receive(name).with(*expected_args).and_call_original + expect(multi_store.default_store).to receive(name).with(*expected_args).and_call_original subject end - include_examples 'verify that store contains values', :secondary_store + include_examples 'verify that store contains values', :default_store end context 'when the command is executed within pipelined block' do @@ -661,21 +673,33 @@ RSpec.describe Gitlab::Redis::MultiStore, feature_category: :redis do include_examples 'verify that store contains values', :secondary_store end - context 'when executing on the primary instance is raising an exception' do + context 'when executing on the default instance is raising an exception' do before do - allow(primary_store).to receive(name).and_raise(StandardError) + allow(multi_store.default_store).to receive(name).and_raise(StandardError) + end + + it 'raises error and does not execute on non default instance', :aggregate_failures do + expect(multi_store.non_default_store).not_to receive(name) + + expect { subject }.to raise_error(StandardError) + end + end + + context 'when executing on the non default instance is raising an exception' do + before do + allow(multi_store.non_default_store).to receive(name).and_raise(StandardError) allow(Gitlab::ErrorTracking).to receive(:log_exception) end - it 'logs the exception and execute on secondary instance', :aggregate_failures do + it 'logs the exception and execute on default instance', :aggregate_failures do expect(Gitlab::ErrorTracking).to receive(:log_exception).with(an_instance_of(StandardError), hash_including(:multi_store_error_message, command_name: name)) - expect(secondary_store).to receive(name).and_call_original + expect(multi_store.default_store).to receive(name).and_call_original subject end - include_examples 'verify that store contains values', :secondary_store + include_examples 'verify that store contains values', :default_store end describe 'return values from a pipelined command' do @@ -708,15 +732,16 @@ RSpec.describe Gitlab::Redis::MultiStore, feature_category: :redis do context 'when the value exists on both but differ' do before do - primary_store.set(key1, value1) - secondary_store.set(key1, value2) + multi_store.non_default_store.set(key1, value1) + multi_store.default_store.set(key1, value2) end it 'returns the value from the secondary store, logging an error' do expect(Gitlab::ErrorTracking).to receive(:log_exception).with( pipeline_diff_error_with_stacktrace( 'Pipelined command executed on both stores successfully but results differ between them. ' \ - "Result from the primary: [#{value1.inspect}]. Result from the secondary: [#{value2.inspect}]." + "Result from the non-default store: [#{value1.inspect}]. " \ + "Result from the default store: [#{value2.inspect}]." ), hash_including(command_name: name, instance_name: instance_name) ).and_call_original @@ -726,16 +751,16 @@ RSpec.describe Gitlab::Redis::MultiStore, feature_category: :redis do end end - context 'when the value does not exist on the primary but it does on the secondary' do + context 'when the value does not exist on the non-default store but it does on the default' do before do - secondary_store.set(key1, value2) + multi_store.default_store.set(key1, value2) end it 'returns the value from the secondary store, logging an error' do expect(Gitlab::ErrorTracking).to receive(:log_exception).with( pipeline_diff_error_with_stacktrace( 'Pipelined command executed on both stores successfully but results differ between them. ' \ - "Result from the primary: [nil]. Result from the secondary: [#{value2.inspect}]." + "Result from the non-default store: [nil]. Result from the default store: [#{value2.inspect}]." ), hash_including(command_name: name, instance_name: instance_name) ) @@ -784,18 +809,24 @@ RSpec.describe Gitlab::Redis::MultiStore, feature_category: :redis do end context 'when either store is a an instance of ::Redis::Cluster' do + let(:pipeline) { double } + let(:client) { double } + before do - client = double allow(client).to receive(:instance_of?).with(::Redis::Cluster).and_return(true) - allow(primary_store).to receive(:_client).and_return(client) + allow(pipeline).to receive(:pipelined) + allow(multi_store.default_store).to receive(:_client).and_return(client) end it 'calls cross-slot pipeline within multistore' do if name == :pipelined # we intentionally exclude `.and_call_original` since primary_store/secondary_store # may not be running on a proper Redis Cluster. - expect(Gitlab::Redis::CrossSlot::Pipeline).to receive(:new).with(primary_store).exactly(:once) - expect(Gitlab::Redis::CrossSlot::Pipeline).not_to receive(:new).with(secondary_store) + expect(Gitlab::Redis::CrossSlot::Pipeline).to receive(:new) + .with(multi_store.default_store) + .exactly(:once) + .and_return(pipeline) + expect(Gitlab::Redis::CrossSlot::Pipeline).not_to receive(:new).with(multi_store.non_default_store) end subject diff --git a/spec/lib/gitlab/slash_commands/presenters/access_spec.rb b/spec/lib/gitlab/slash_commands/presenters/access_spec.rb index 5d62e96971b..3af0ae03256 100644 --- a/spec/lib/gitlab/slash_commands/presenters/access_spec.rb +++ b/spec/lib/gitlab/slash_commands/presenters/access_spec.rb @@ -38,7 +38,7 @@ RSpec.describe Gitlab::SlashCommands::Presenters::Access do it { is_expected.to be_a(Hash) } it_behaves_like 'displays an error message' do - let(:error_message) { 'your account has been deactivated by your administrator' } + let(:error_message) { "your #{Gitlab.config.gitlab.url} account needs to be reactivated" } end end diff --git a/spec/support/shared_examples/models/integrations/base_slash_commands_shared_examples.rb b/spec/support/shared_examples/models/integrations/base_slash_commands_shared_examples.rb index 0cf109ce5c5..ff3cc1841b4 100644 --- a/spec/support/shared_examples/models/integrations/base_slash_commands_shared_examples.rb +++ b/spec/support/shared_examples/models/integrations/base_slash_commands_shared_examples.rb @@ -122,7 +122,7 @@ RSpec.shared_examples Integrations::BaseSlashCommands do end it_behaves_like 'blocks command execution' do - let(:error_message) { 'your account has been deactivated by your administrator' } + let(:error_message) { "your #{Gitlab.config.gitlab.url} account needs to be reactivated" } end end end |