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

require 'spec_helper'

RSpec.describe Gitlab::Database::PostgresAutovacuumActivity, type: :model do
  include Database::DatabaseHelpers

  it { is_expected.to be_a Gitlab::Database::SharedModel }

  describe '.for_tables' do
    subject { described_class.for_tables(tables) }

    let(:tables) { %w[foo test] }

    before do
      swapout_view_for_table(:postgres_autovacuum_activity)

      # unrelated
      create(:postgres_autovacuum_activity, table: 'bar')

      tables.each do |table|
        create(:postgres_autovacuum_activity, table: table)
      end

      expect(Gitlab::Database::LoadBalancing::Session.current).to receive(:use_primary).and_yield
    end

    it 'returns autovacuum activity for queries tables' do
      expect(subject.map(&:table).sort).to eq(tables)
    end
  end
end