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::Subscribers::ActionView do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:env) { {} }
|
|
|
|
let(:transaction) { Gitlab::Metrics::WebTransaction.new(env) }
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
let(:subscriber) { described_class.new }
|
|
|
|
|
|
|
|
let(:event) do
|
|
|
|
root = Rails.root.to_s
|
|
|
|
|
|
|
|
double(:event, duration: 2.1,
|
|
|
|
payload: { identifier: "#{root}/app/views/x.html.haml" })
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(subscriber).to receive(:current_transaction).and_return(transaction)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#render_template' do
|
|
|
|
it 'tracks rendering of a template' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(transaction).to receive(:increment)
|
2020-10-24 23:57:45 +05:30
|
|
|
.with(:gitlab_transaction_view_duration_total, 2.1)
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
subscriber.render_template(event)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it 'observes view rendering time' do
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(transaction)
|
2018-03-17 18:26:18 +05:30
|
|
|
.to receive(:observe)
|
2020-10-24 23:57:45 +05:30
|
|
|
.with(:gitlab_view_rendering_duration_seconds, 2.1, { view: "app/views/x.html.haml" })
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
subscriber.render_template(event)
|
|
|
|
end
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
end
|