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

total_count_metric_spec.rb « instrumentations « metrics « usage « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f3aa1ba4f88d8168e53fdc1236f6fd85412cde5e (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Usage::Metrics::Instrumentations::TotalCountMetric, :clean_gitlab_redis_shared_state,
  feature_category: :product_analytics_data_management do
  before do
    allow(Gitlab::InternalEvents::EventDefinitions).to receive(:known_event?).and_return(true)
  end

  context 'with multiple similar events' do
    let(:expected_value) { 10 }

    before do
      10.times do
        Gitlab::InternalEvents.track_event('my_event')
      end
    end

    it_behaves_like 'a correct instrumented metric value', { time_frame: 'all', events: [{ name: 'my_event' }] }
  end

  context 'with multiple different events' do
    let(:expected_value) { 2 }

    before do
      Gitlab::InternalEvents.track_event('my_event1')
      Gitlab::InternalEvents.track_event('my_event2')
    end

    it_behaves_like 'a correct instrumented metric value',
      { time_frame: 'all', events: [{ name: 'my_event1' }, { name: 'my_event2' }] }
  end

  describe '.redis_key' do
    it 'adds the key prefix to the event name' do
      expect(described_class.redis_key('my_event')).to eq('{event_counters}_my_event')
    end
  end
end