Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-24 15:12:07 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-24 15:12:07 +0300
commit263baf70a1f64bb773bfb57d74516a008c2bc7e4 (patch)
tree3fd07a2e7bccc2f6d19a1423c322240bd9808234 /spec/support
parent0086677f7cad8c0d7e73d8584ce317f1fce5534e (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/rspec_order.rb5
-rw-r--r--spec/support/shared_examples/lib/cache_helpers_shared_examples.rb117
2 files changed, 118 insertions, 4 deletions
diff --git a/spec/support/rspec_order.rb b/spec/support/rspec_order.rb
index 58f1fe29357..e9a33dd7bea 100644
--- a/spec/support/rspec_order.rb
+++ b/spec/support/rspec_order.rb
@@ -43,9 +43,6 @@ RSpec.configure do |config|
config.on_example_group_definition do |example_group|
order = Support::RspecOrder.order_for(example_group)
- if order
- example_group.metadata[:order] = order.to_sym
- example_group.metadata[:description] += " (order #{order})"
- end
+ example_group.metadata[:order] = order.to_sym if order
end
end
diff --git a/spec/support/shared_examples/lib/cache_helpers_shared_examples.rb b/spec/support/shared_examples/lib/cache_helpers_shared_examples.rb
index 845fa78a827..495ea931728 100644
--- a/spec/support/shared_examples/lib/cache_helpers_shared_examples.rb
+++ b/spec/support/shared_examples/lib/cache_helpers_shared_examples.rb
@@ -43,6 +43,54 @@ RSpec.shared_examples_for 'object cache helper' do
subject
end
end
+
+ context 'when a caller id is present' do
+ let(:transaction) { Gitlab::Metrics::WebTransaction.new({}) }
+ let(:caller_id) { 'caller_id' }
+
+ before do
+ allow(::Gitlab::Metrics::WebTransaction).to receive(:current).and_return(transaction)
+ allow(transaction).to receive(:increment)
+ allow(Gitlab::ApplicationContext).to receive(:current_context_attribute).with(:caller_id).and_return(caller_id)
+ end
+
+ context 'when feature flag is off' do
+ before do
+ stub_feature_flags(add_timing_to_certain_cache_actions: false)
+ end
+
+ it 'does not call increment' do
+ expect(transaction).not_to receive(:increment).with(:cached_object_operations_total, any_args)
+
+ subject
+ end
+
+ it 'does not call histogram' do
+ expect(Gitlab::Metrics).not_to receive(:histogram)
+
+ subject
+ end
+
+ it "is valid JSON" do
+ parsed = Gitlab::Json.parse(subject.to_s)
+
+ expect(parsed).to be_a(Hash)
+ expect(parsed["id"]).to eq(presentable.id)
+ end
+ end
+
+ it 'increments the counter' do
+ expect(transaction)
+ .to receive(:increment)
+ .with(:cached_object_operations_total, 1, { caller_id: caller_id, render_type: :object, cache_hit: false }).once
+
+ expect(transaction)
+ .to receive(:increment)
+ .with(:cached_object_operations_total, 0, { caller_id: caller_id, render_type: :object, cache_hit: true }).once
+
+ subject
+ end
+ end
end
RSpec.shared_examples_for 'collection cache helper' do
@@ -98,4 +146,73 @@ RSpec.shared_examples_for 'collection cache helper' do
subject
end
end
+
+ context 'when a caller id is present' do
+ let(:transaction) { Gitlab::Metrics::WebTransaction.new({}) }
+ let(:caller_id) { 'caller_id' }
+
+ before do
+ allow(::Gitlab::Metrics::WebTransaction).to receive(:current).and_return(transaction)
+ allow(transaction).to receive(:increment)
+ allow(Gitlab::ApplicationContext).to receive(:current_context_attribute).with(:caller_id).and_return(caller_id)
+ end
+
+ context 'when feature flag is off' do
+ before do
+ stub_feature_flags(add_timing_to_certain_cache_actions: false)
+ end
+
+ it 'does not call increment' do
+ expect(transaction).not_to receive(:increment).with(:cached_object_operations_total, any_args)
+
+ subject
+ end
+
+ it 'does not call histogram' do
+ expect(Gitlab::Metrics).not_to receive(:histogram)
+
+ subject
+ end
+
+ it "is valid JSON" do
+ parsed = Gitlab::Json.parse(subject.to_s)
+
+ expect(parsed).to be_an(Array)
+
+ presentable.each_with_index do |item, i|
+ expect(parsed[i]["id"]).to eq(item.id)
+ end
+ end
+ end
+
+ context 'when the presentables all miss' do
+ it 'increments the counters' do
+ expect(transaction)
+ .to receive(:increment)
+ .with(:cached_object_operations_total, 0, { caller_id: caller_id, render_type: :collection, cache_hit: true }).once
+
+ expect(transaction)
+ .to receive(:increment)
+ .with(:cached_object_operations_total, presentable.size, { caller_id: caller_id, render_type: :collection, cache_hit: false }).once
+
+ subject
+ end
+ end
+
+ context 'when the presents hit' do
+ it 'increments the counters' do
+ subject
+
+ expect(transaction)
+ .to receive(:increment)
+ .with(:cached_object_operations_total, presentable.size, { caller_id: caller_id, render_type: :collection, cache_hit: true }).once
+
+ expect(transaction)
+ .to receive(:increment)
+ .with(:cached_object_operations_total, 0, { caller_id: caller_id, render_type: :collection, cache_hit: false }).once
+
+ instance.public_send(method, presentable, **kwargs)
+ end
+ end
+ end
end