summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/database/partitioning/partition_monitoring_spec.rb
blob: 7024cbd55ffa771a5e7b790d96b382c8a37c0909 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Database::Partitioning::PartitionMonitoring do
  describe '#report_metrics' do
    subject { described_class.new(models).report_metrics }

    let(:models) { [model] }
    let(:model) { double(partitioning_strategy: partitioning_strategy, table_name: table) }
    let(:partitioning_strategy) { double(missing_partitions: missing_partitions, current_partitions: current_partitions, extra_partitions: extra_partitions) }
    let(:table) { "some_table" }

    let(:missing_partitions) do
      [double]
    end

    let(:current_partitions) do
      [double, double]
    end

    let(:extra_partitions) do
      [double, double, double]
    end

    it 'reports number of present partitions' do
      subject

      expect(Gitlab::Metrics.registry.get(:db_partitions_present).get({ table: table })).to eq(current_partitions.size)
    end

    it 'reports number of missing partitions' do
      subject

      expect(Gitlab::Metrics.registry.get(:db_partitions_missing).get({ table: table })).to eq(missing_partitions.size)
    end

    it 'reports number of extra partitions' do
      subject

      expect(Gitlab::Metrics.registry.get(:db_partitions_extra).get({ table: table })).to eq(extra_partitions.size)
    end
  end
end