summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/metrics/background_transaction_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 13:16:36 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 13:16:36 +0000
commit311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch)
tree07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/lib/gitlab/metrics/background_transaction_spec.rb
parent27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff)
downloadgitlab-ce-311b0269b4eb9839fa63f80c8d7a58f32b8138a0.tar.gz
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/lib/gitlab/metrics/background_transaction_spec.rb')
-rw-r--r--spec/lib/gitlab/metrics/background_transaction_spec.rb47
1 files changed, 14 insertions, 33 deletions
diff --git a/spec/lib/gitlab/metrics/background_transaction_spec.rb b/spec/lib/gitlab/metrics/background_transaction_spec.rb
index d36ee24fc50..83bee84df99 100644
--- a/spec/lib/gitlab/metrics/background_transaction_spec.rb
+++ b/spec/lib/gitlab/metrics/background_transaction_spec.rb
@@ -4,27 +4,28 @@ require 'spec_helper'
RSpec.describe Gitlab::Metrics::BackgroundTransaction do
let(:transaction) { described_class.new }
- let(:prometheus_metric) { instance_double(Prometheus::Client::Metric, base_labels: {}) }
-
- before do
- allow(described_class).to receive(:prometheus_metric).and_return(prometheus_metric)
- end
describe '#run' do
+ let(:prometheus_metric) { instance_double(Prometheus::Client::Metric, base_labels: {}) }
+
+ before do
+ allow(described_class).to receive(:prometheus_metric).and_return(prometheus_metric)
+ end
+
it 'yields the supplied block' do
expect { |b| transaction.run(&b) }.to yield_control
end
it 'stores the transaction in the current thread' do
transaction.run do
- expect(Thread.current[described_class::BACKGROUND_THREAD_KEY]).to eq(transaction)
+ expect(Thread.current[described_class::THREAD_KEY]).to eq(transaction)
end
end
it 'removes the transaction from the current thread upon completion' do
transaction.run { }
- expect(Thread.current[described_class::BACKGROUND_THREAD_KEY]).to be_nil
+ expect(Thread.current[described_class::THREAD_KEY]).to be_nil
end
end
@@ -68,7 +69,10 @@ RSpec.describe Gitlab::Metrics::BackgroundTransaction do
end
end
- RSpec.shared_examples 'metric with labels' do |metric_method|
+ it_behaves_like 'transaction metrics with labels' do
+ let(:transaction_obj) { described_class.new }
+ let(:labels) { { endpoint_id: 'TestWorker', feature_category: 'projects', queue: 'test_worker' } }
+
before do
test_worker_class = Class.new do
def self.queue
@@ -78,33 +82,10 @@ RSpec.describe Gitlab::Metrics::BackgroundTransaction do
stub_const('TestWorker', test_worker_class)
end
- it 'measures with correct labels and value' do
- value = 1
- expect(prometheus_metric).to receive(metric_method).with({
- endpoint_id: 'TestWorker', feature_category: 'projects', queue: 'test_worker'
- }, value)
-
+ around do |example|
Gitlab::ApplicationContext.with_raw_context(feature_category: 'projects', caller_id: 'TestWorker') do
- transaction.send(metric_method, :test_metric, value)
+ example.run
end
end
end
-
- describe '#increment' do
- let(:prometheus_metric) { instance_double(Prometheus::Client::Counter, :increment, base_labels: {}) }
-
- it_behaves_like 'metric with labels', :increment
- end
-
- describe '#set' do
- let(:prometheus_metric) { instance_double(Prometheus::Client::Gauge, :set, base_labels: {}) }
-
- it_behaves_like 'metric with labels', :set
- end
-
- describe '#observe' do
- let(:prometheus_metric) { instance_double(Prometheus::Client::Histogram, :observe, base_labels: {}) }
-
- it_behaves_like 'metric with labels', :observe
- end
end