2020-04-23 14:09:46 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'fast_spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::Utils::Measuring do
|
2020-04-23 14:09:46 -04:00
|
|
|
describe '#with_measuring' do
|
|
|
|
let(:base_log_data) { {} }
|
|
|
|
let(:result) { "result" }
|
|
|
|
|
|
|
|
before do
|
2021-06-08 11:10:00 -04:00
|
|
|
allow(ActiveSupport::Logger).to receive(:logger_outputs_to?).with(Gitlab::Utils::Measuring.logger, $stdout).and_return(false)
|
2020-04-23 14:09:46 -04:00
|
|
|
end
|
|
|
|
|
2020-05-13 08:07:54 -04:00
|
|
|
let(:measurement) { described_class.new(base_log_data) }
|
2020-04-23 14:09:46 -04:00
|
|
|
|
|
|
|
subject do
|
|
|
|
measurement.with_measuring { result }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'measures and logs data', :aggregate_failure do
|
|
|
|
expect(measurement).to receive(:with_measure_time).and_call_original
|
|
|
|
expect(measurement).to receive(:with_count_queries).and_call_original
|
|
|
|
expect(measurement).to receive(:with_gc_stats).and_call_original
|
|
|
|
|
2020-05-13 08:07:54 -04:00
|
|
|
expect(described_class.logger).to receive(:info).with(include(:gc_stats, :time_to_finish, :number_of_sql_calls, :memory_usage, :label))
|
2020-04-23 14:09:46 -04:00
|
|
|
|
|
|
|
is_expected.to eq(result)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with base_log_data provided' do
|
|
|
|
let(:base_log_data) { { test: "data" } }
|
|
|
|
|
|
|
|
it 'logs includes base data' do
|
2020-05-13 08:07:54 -04:00
|
|
|
expect(described_class.logger).to receive(:info).with(include(:test, :gc_stats, :time_to_finish, :number_of_sql_calls, :memory_usage, :label))
|
2020-04-23 14:09:46 -04:00
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|