2016-01-14 18:37:52 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Metrics::SidekiqMiddleware do
|
|
|
|
let(:middleware) { described_class.new }
|
2016-08-24 12:49:21 +05:30
|
|
|
let(:message) { { 'args' => ['test'], 'enqueued_at' => Time.new(2016, 6, 23, 6, 59).to_f } }
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
describe '#call' do
|
|
|
|
it 'tracks the transaction' do
|
|
|
|
worker = double(:worker, class: double(:class, name: 'TestWorker'))
|
|
|
|
|
|
|
|
expect(Gitlab::Metrics::Transaction).to receive(:new).
|
|
|
|
with('TestWorker#perform').
|
|
|
|
and_call_original
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
expect_any_instance_of(Gitlab::Metrics::Transaction).to receive(:set).
|
|
|
|
with(:sidekiq_queue_duration, instance_of(Float))
|
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
expect_any_instance_of(Gitlab::Metrics::Transaction).to receive(:finish)
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
middleware.call(worker, message, :test) { nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tracks the transaction (for messages without `enqueued_at`)' do
|
|
|
|
worker = double(:worker, class: double(:class, name: 'TestWorker'))
|
|
|
|
|
|
|
|
expect(Gitlab::Metrics::Transaction).to receive(:new).
|
|
|
|
with('TestWorker#perform').
|
|
|
|
and_call_original
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
expect_any_instance_of(Gitlab::Metrics::Transaction).to receive(:set).
|
|
|
|
with(:sidekiq_queue_duration, instance_of(Float))
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
expect_any_instance_of(Gitlab::Metrics::Transaction).to receive(:finish)
|
|
|
|
|
|
|
|
middleware.call(worker, {}, :test) { nil }
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
it 'tracks any raised exceptions' do
|
|
|
|
worker = double(:worker, class: double(:class, name: 'TestWorker'))
|
|
|
|
|
|
|
|
expect_any_instance_of(Gitlab::Metrics::Transaction).
|
|
|
|
to receive(:run).and_raise(RuntimeError)
|
|
|
|
|
|
|
|
expect_any_instance_of(Gitlab::Metrics::Transaction).
|
|
|
|
to receive(:add_event).with(:sidekiq_exception)
|
|
|
|
|
|
|
|
expect_any_instance_of(Gitlab::Metrics::Transaction).
|
|
|
|
to receive(:finish)
|
|
|
|
|
|
|
|
expect { middleware.call(worker, message, :test) }.
|
|
|
|
to raise_error(RuntimeError)
|
|
|
|
end
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
end
|