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

detailed_view_spec.rb « views « peek « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8d6d9a829ef0a251b9c34f6e5c30114765e6c91a (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# frozen_string_literal: true

require 'fast_spec_helper'

RSpec.describe Peek::Views::DetailedView, :request_store do
  context 'when a class defines thresholds' do
    let(:threshold_view) do
      Class.new(described_class) do
        def self.thresholds
          {
            calls: 1,
            duration: 10,
            individual_call: 5
          }
        end

        def key
          'threshold-view'
        end
      end.new
    end

    context 'when the results exceed the calls threshold' do
      before do
        allow(threshold_view)
          .to receive(:detail_store).and_return([{ duration: 0.001 }, { duration: 0.001 }])
      end

      it 'adds a warning to the results key' do
        expect(threshold_view.results).to include(warnings: [a_string_matching('threshold-view calls')])
      end
    end

    context 'when the results exceed the duration threshold' do
      before do
        allow(threshold_view)
          .to receive(:detail_store).and_return([{ duration: 0.011 }])
      end

      it 'adds a warning to the results key' do
        expect(threshold_view.results).to include(warnings: [a_string_matching('threshold-view duration')])
      end
    end

    context 'when a single call exceeds the duration threshold' do
      before do
        allow(threshold_view)
          .to receive(:detail_store).and_return([{ duration: 0.001 }, { duration: 0.006 }])
      end

      it 'adds a warning to that call detail entry' do
        expect(threshold_view.results)
          .to include(details: a_collection_containing_exactly(
            { duration: 1.0, warnings: [] },
                       { duration: 6.0, warnings: ['6.0 over 5'] }
          ))
      end
    end
  end

  context 'when a view does not define thresholds' do
    let(:no_threshold_view) { Class.new(described_class).new }

    before do
      allow(no_threshold_view)
        .to receive(:detail_store).and_return([{ duration: 100 }, { duration: 100 }])
    end

    it 'does not add warnings to the top level' do
      expect(no_threshold_view.results).to include(warnings: [])
    end

    it 'does not add warnings to call details entries' do
      expect(no_threshold_view.results)
        .to include(details: a_collection_containing_exactly(
          { duration: 100000, warnings: [] },
                     { duration: 100000, warnings: [] }
        ))
    end
  end
end