2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
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
|
|
|
|
|
|
|
|
describe '#transaction_from_env' do
|
|
|
|
let(:transaction) { middleware.transaction_from_env(env) }
|
|
|
|
|
|
|
|
it 'returns a Transaction' do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(transaction).to be_an_instance_of(Gitlab::Metrics::WebTransaction)
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|