summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/database/background_migration/batch_metrics_spec.rb
blob: 669837334116ddf14dce13e9fd2e0b387431223c (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Database::BackgroundMigration::BatchMetrics do
  let(:batch_metrics) { described_class.new }

  describe '#time_operation' do
    it 'tracks the duration of the operation using monotonic time' do
      expect(batch_metrics.timings).to be_empty

      expect(Gitlab::Metrics::System).to receive(:monotonic_time)
        .exactly(6).times
        .and_return(0.0, 111.0, 200.0, 290.0, 300.0, 410.0)

      batch_metrics.time_operation(:my_label) do
        # some operation
      end

      batch_metrics.time_operation(:my_other_label) do
        # some operation
      end

      batch_metrics.time_operation(:my_label) do
        # some operation
      end

      expect(batch_metrics.timings).to eq(my_label: [111.0, 110.0], my_other_label: [90.0])
    end
  end
end