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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/database/migrations/observers/total_database_size_change_spec.rb')
-rw-r--r--spec/lib/gitlab/database/migrations/observers/total_database_size_change_spec.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/lib/gitlab/database/migrations/observers/total_database_size_change_spec.rb b/spec/lib/gitlab/database/migrations/observers/total_database_size_change_spec.rb
new file mode 100644
index 00000000000..73466471944
--- /dev/null
+++ b/spec/lib/gitlab/database/migrations/observers/total_database_size_change_spec.rb
@@ -0,0 +1,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