diff options
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/database/postgres_index_spec.rb | 14 | ||||
-rw-r--r-- | spec/lib/gitlab/database/reindexing/concurrent_reindex_spec.rb | 22 | ||||
-rw-r--r-- | spec/lib/gitlab/database/reindexing_spec.rb | 11 |
3 files changed, 45 insertions, 2 deletions
diff --git a/spec/lib/gitlab/database/postgres_index_spec.rb b/spec/lib/gitlab/database/postgres_index_spec.rb index 2a9598736ed..1da67a5a6c0 100644 --- a/spec/lib/gitlab/database/postgres_index_spec.rb +++ b/spec/lib/gitlab/database/postgres_index_spec.rb @@ -30,7 +30,7 @@ RSpec.describe Gitlab::Database::PostgresIndex do end end - describe '#regular' do + describe '.regular' do it 'only non-unique indexes' do expect(described_class.regular).to all(have_attributes(unique: false)) end @@ -44,7 +44,17 @@ RSpec.describe Gitlab::Database::PostgresIndex do end end - describe '#random_few' do + describe '.not_match' do + it 'excludes indexes matching the given regex' do + expect(described_class.not_match('^bar_k').map(&:name)).to all(match(/^(?!bar_k).*/)) + end + + it 'matches indexes without this prefix regex' do + expect(described_class.not_match('^bar_k')).not_to be_empty + end + end + + describe '.random_few' do it 'limits to two records by default' do expect(described_class.random_few(2).size).to eq(2) end diff --git a/spec/lib/gitlab/database/reindexing/concurrent_reindex_spec.rb b/spec/lib/gitlab/database/reindexing/concurrent_reindex_spec.rb index 49087e7ff2c..a80bf8176d2 100644 --- a/spec/lib/gitlab/database/reindexing/concurrent_reindex_spec.rb +++ b/spec/lib/gitlab/database/reindexing/concurrent_reindex_spec.rb @@ -58,6 +58,28 @@ RSpec.describe Gitlab::Database::Reindexing::ConcurrentReindex, '#perform' do end end + context 'when the index is a lingering temporary index from a previous reindexing run' do + context 'with the temporary index prefix' do + let(:index_name) { 'tmp_reindex_something' } + + it 'raises an error' do + expect do + subject.perform + end.to raise_error(described_class::ReindexError, /left-over temporary index/) + end + end + + context 'with the replaced index prefix' do + let(:index_name) { 'old_reindex_something' } + + it 'raises an error' do + expect do + subject.perform + end.to raise_error(described_class::ReindexError, /left-over temporary index/) + end + end + end + context 'replacing the original index with a rebuilt copy' do let(:replacement_name) { 'tmp_reindex_42' } let(:replaced_name) { 'old_reindex_42' } diff --git a/spec/lib/gitlab/database/reindexing_spec.rb b/spec/lib/gitlab/database/reindexing_spec.rb index 32580ae9e3a..26954a9a32f 100644 --- a/spec/lib/gitlab/database/reindexing_spec.rb +++ b/spec/lib/gitlab/database/reindexing_spec.rb @@ -52,4 +52,15 @@ RSpec.describe Gitlab::Database::Reindexing do it_behaves_like 'reindexing' end end + + describe '.candidate_indexes' do + subject { described_class.candidate_indexes } + + it 'retrieves regular indexes that are no left-overs from previous runs' do + result = double + expect(Gitlab::Database::PostgresIndex).to receive_message_chain('regular.not_match.not_match').with(no_args).with('^tmp_reindex_').with('^old_reindex_').and_return(result) + + expect(subject).to eq(result) + end + end end |