Welcome to mirror list, hosted at ThFree Co, Russian Federation.

queue_duration_logger_spec.rb « loggers « grape_logging « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4cd9f9dfad07698574787fa89fbead225e6770b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::GrapeLogging::Loggers::QueueDurationLogger do
  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) { double('env', 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
        double('env',
          env: {
            'HTTP_GITLAB_WORKHORSE_PROXY_START' => (start_time - 1.hour).to_i * (10**9)
          }
        )
      end

      it 'returns the correct duration in seconds' do
        travel_to(start_time) do
          subject.before

          expect(subject.parameters(mock_request, nil)).to eq( { 'queue_duration_s': 1.hour.to_f })
        end
      end
    end
  end
end