2021-01-03 14:25:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Gitlab::Database::Reindexing do
|
|
|
|
include ExclusiveLeaseHelpers
|
|
|
|
|
|
|
|
describe '.perform' do
|
2021-02-22 17:27:13 +05:30
|
|
|
subject { described_class.perform(candidate_indexes) }
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
let(:coordinator) { instance_double(Gitlab::Database::Reindexing::Coordinator) }
|
2021-02-22 17:27:13 +05:30
|
|
|
let(:index_selection) { instance_double(Gitlab::Database::Reindexing::IndexSelection) }
|
|
|
|
let(:candidate_indexes) { double }
|
2021-03-08 18:12:59 +05:30
|
|
|
let(:indexes) { [double, double] }
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
it 'delegates to Coordinator' do
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(Gitlab::Database::Reindexing::IndexSelection).to receive(:new).with(candidate_indexes).and_return(index_selection)
|
|
|
|
expect(index_selection).to receive(:take).with(2).and_return(indexes)
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
indexes.each do |index|
|
|
|
|
expect(Gitlab::Database::Reindexing::Coordinator).to receive(:new).with(index).and_return(coordinator)
|
|
|
|
expect(coordinator).to receive(:perform)
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
subject
|
|
|
|
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
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(Gitlab::Database::PostgresIndex).to receive_message_chain('regular.where.not_match.not_match').with(no_args).with('NOT expression').with('^tmp_reindex_').with('^old_reindex_').and_return(result)
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
expect(subject).to eq(result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|