2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
require 'fast_spec_helper'
|
2016-01-14 18:37:52 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Metrics::RackMiddleware do
|
2016-01-14 18:37:52 +05:30
|
|
|
let(:app) { double(:app) }
|
|
|
|
|
|
|
|
let(:middleware) { described_class.new(app) }
|
|
|
|
|
|
|
|
let(:env) { { 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/foo' } }
|
|
|
|
|
|
|
|
describe '#call' do
|
|
|
|
it 'tracks a transaction' do
|
|
|
|
expect(app).to receive(:call).with(env).and_return('yay')
|
|
|
|
|
|
|
|
expect(middleware.call(env)).to eq('yay')
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'tracks any raised exceptions' do
|
|
|
|
expect(app).to receive(:call).with(env).and_raise(RuntimeError)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect_any_instance_of(Gitlab::Metrics::Transaction)
|
|
|
|
.to receive(:add_event).with(:rails_exception)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
expect { middleware.call(env) }.to raise_error(RuntimeError)
|
|
|
|
end
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
end
|