2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::GrapeLogging::Loggers::QueueDurationLogger do
|
2018-11-08 19:23:39 +05:30
|
|
|
subject { described_class.new }
|
|
|
|
|
|
|
|
describe ".parameters" do
|
|
|
|
let(:start_time) { Time.new(2018, 01, 01) }
|
|
|
|
|
|
|
|
describe 'when no proxy time is available' do
|
|
|
|
let(:mock_request) { OpenStruct.new(env: {}) }
|
|
|
|
|
|
|
|
it 'returns an empty hash' do
|
|
|
|
expect(subject.parameters(mock_request, nil)).to eq({})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when a proxy time is available' do
|
|
|
|
let(:mock_request) do
|
|
|
|
OpenStruct.new(
|
|
|
|
env: {
|
|
|
|
'HTTP_GITLAB_WORKHORSE_PROXY_START' => (start_time - 1.hour).to_i * (10**9)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'returns the correct duration in seconds' do
|
2021-01-03 14:25:43 +05:30
|
|
|
travel_to(start_time) do
|
2018-11-08 19:23:39 +05:30
|
|
|
subject.before
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(subject.parameters(mock_request, nil)).to eq( { 'queue_duration_s': 1.hour.to_f })
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|