summaryrefslogtreecommitdiff
path: root/spec/support_specs
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-03-15 18:11:11 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-03-15 18:11:11 +0000
commitf6b58d14904a1413a5442d13f361671e59ab3ded (patch)
tree5120b75e5d2bfa1773f9c5e431521afef652a8c4 /spec/support_specs
parentce97c898865e06644ae9c04d5c3666775b9998cb (diff)
downloadgitlab-ce-f6b58d14904a1413a5442d13f361671e59ab3ded.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support_specs')
-rw-r--r--spec/support_specs/matchers/exceed_redis_call_limit_spec.rb59
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/support_specs/matchers/exceed_redis_call_limit_spec.rb b/spec/support_specs/matchers/exceed_redis_call_limit_spec.rb
new file mode 100644
index 00000000000..819f50e26b6
--- /dev/null
+++ b/spec/support_specs/matchers/exceed_redis_call_limit_spec.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'RedisCommand matchers', :use_clean_rails_redis_caching, feature_category: :source_code_management do
+ let(:control) do
+ RedisCommands::Recorder.new do
+ Rails.cache.read('test')
+ Rails.cache.read('test')
+ Rails.cache.write('test', 1)
+ end
+ end
+
+ before do
+ Rails.cache.read('warmup')
+ end
+
+ it 'verifies maximum number of Redis calls' do
+ expect(control).not_to exceed_redis_calls_limit(3)
+
+ expect(control).not_to exceed_redis_command_calls_limit(:get, 2)
+ expect(control).not_to exceed_redis_command_calls_limit(:set, 1)
+ end
+
+ it 'verifies minimum number of Redis calls' do
+ expect(control).to exceed_redis_calls_limit(2)
+
+ expect(control).to exceed_redis_command_calls_limit(:get, 1)
+ expect(control).to exceed_redis_command_calls_limit(:set, 0)
+ end
+
+ context 'with Recorder matching only some Redis calls' do
+ it 'counts only Redis calls captured by Recorder' do
+ Rails.cache.write('ignored', 1)
+
+ control = RedisCommands::Recorder.new do
+ Rails.cache.read('recorded')
+ end
+
+ Rails.cache.write('also_ignored', 1)
+
+ expect(control).not_to exceed_redis_calls_limit(1)
+ expect(control).not_to exceed_redis_command_calls_limit(:set, 0)
+ expect(control).not_to exceed_redis_command_calls_limit(:get, 1)
+ end
+ end
+
+ context 'when expect part is a function' do
+ it 'automatically enables RedisCommand::Recorder for it' do
+ func = -> do
+ Rails.cache.read('test')
+ Rails.cache.read('test')
+ end
+
+ expect { func.call }.not_to exceed_redis_calls_limit(2)
+ expect { func.call }.not_to exceed_redis_command_calls_limit(:get, 2)
+ end
+ end
+end