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

total_database_size_change_spec.rb « observers « migrations « database « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 73466471944f41e87c22ea0e77712cd75ac645e0 (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
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe Gitlab::Database::Migrations::Observers::TotalDatabaseSizeChange do
  subject { described_class.new }

  let(:observation) { Gitlab::Database::Migrations::Observation.new }
  let(:connection) { ActiveRecord::Base.connection }
  let(:query) { 'select pg_database_size(current_database())' }

  it 'records the size change' do
    expect(connection).to receive(:execute).with(query).once.and_return([{ 'pg_database_size' => 1024 }])
    expect(connection).to receive(:execute).with(query).once.and_return([{ 'pg_database_size' => 256 }])

    subject.before
    subject.after
    subject.record(observation)

    expect(observation.total_database_size_change).to eq(256 - 1024)
  end

  context 'out of order calls' do
    before do
      allow(connection).to receive(:execute).with(query).and_return([{ 'pg_database_size' => 1024 }])
    end

    it 'does not record anything if before size is unknown' do
      subject.after

      expect { subject.record(observation) }.not_to change { observation.total_database_size_change }
    end

    it 'does not record anything if after size is unknown' do
      subject.before

      expect { subject.record(observation) }.not_to change { observation.total_database_size_change }
    end
  end
end