summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/database/postgres_index_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/database/postgres_index_spec.rb')
-rw-r--r--spec/lib/gitlab/database/postgres_index_spec.rb48
1 files changed, 41 insertions, 7 deletions
diff --git a/spec/lib/gitlab/database/postgres_index_spec.rb b/spec/lib/gitlab/database/postgres_index_spec.rb
index 2fda9b85c5a..e1832219ebf 100644
--- a/spec/lib/gitlab/database/postgres_index_spec.rb
+++ b/spec/lib/gitlab/database/postgres_index_spec.rb
@@ -22,17 +22,23 @@ RSpec.describe Gitlab::Database::PostgresIndex do
it_behaves_like 'a postgres model'
- describe '.regular' do
- it 'only non-unique indexes' do
- expect(described_class.regular).to all(have_attributes(unique: false))
- end
-
+ describe '.reindexing_support' do
it 'only non partitioned indexes' do
- expect(described_class.regular).to all(have_attributes(partitioned: false))
+ expect(described_class.reindexing_support).to all(have_attributes(partitioned: false))
end
it 'only indexes that dont serve an exclusion constraint' do
- expect(described_class.regular).to all(have_attributes(exclusion: false))
+ expect(described_class.reindexing_support).to all(have_attributes(exclusion: false))
+ end
+
+ it 'only non-expression indexes' do
+ expect(described_class.reindexing_support).to all(have_attributes(expression: false))
+ end
+
+ it 'only btree and gist indexes' do
+ types = described_class.reindexing_support.map(&:type).uniq
+
+ expect(types & %w(btree gist)).to eq(types)
end
end
@@ -67,6 +73,34 @@ RSpec.describe Gitlab::Database::PostgresIndex do
end
end
+ describe '#relative_bloat_level' do
+ subject { build(:postgres_index, bloat_estimate: bloat_estimate, ondisk_size_bytes: 1024) }
+
+ let(:bloat_estimate) { build(:postgres_index_bloat_estimate, bloat_size: 256) }
+
+ it 'calculates the relative bloat level' do
+ expect(subject.relative_bloat_level).to eq(0.25)
+ end
+ end
+
+ describe '#reset' do
+ subject { index.reset }
+
+ let(:index) { described_class.by_identifier(identifier) }
+
+ it 'calls #reload' do
+ expect(index).to receive(:reload).once.and_call_original
+
+ subject
+ end
+
+ it 'resets the bloat estimation' do
+ expect(index).to receive(:clear_memoization).with(:bloat_size).and_call_original
+
+ subject
+ end
+ end
+
describe '#unique?' do
it 'returns true for a unique index' do
expect(find('public.bar_key')).to be_unique