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

reindexing_spec.rb « database « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 26954a9a32f0f7569c43a9a6e516dfff3ad51263 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Database::Reindexing do
  describe '.perform' do
    before do
      allow(Gitlab::Database::Reindexing::ReindexAction).to receive(:keep_track_of).and_yield
    end

    shared_examples_for 'reindexing' do
      before do
        indexes.zip(reindexers).each do |index, reindexer|
          allow(Gitlab::Database::Reindexing::ConcurrentReindex).to receive(:new).with(index).and_return(reindexer)
          allow(reindexer).to receive(:perform)
        end
      end

      it 'performs concurrent reindexing for each index' do
        indexes.zip(reindexers).each do |index, reindexer|
          expect(Gitlab::Database::Reindexing::ConcurrentReindex).to receive(:new).with(index).ordered.and_return(reindexer)
          expect(reindexer).to receive(:perform)
        end

        subject
      end

      it 'keeps track of actions and creates ReindexAction records' do
        indexes.each do |index|
          expect(Gitlab::Database::Reindexing::ReindexAction).to receive(:keep_track_of).with(index).and_yield
        end

        subject
      end
    end

    context 'with multiple indexes' do
      subject { described_class.perform(indexes) }

      let(:indexes) { [instance_double('Gitlab::Database::PostgresIndex'), instance_double('Gitlab::Database::PostgresIndex')] }
      let(:reindexers) { [instance_double('Gitlab::Database::Reindexing::ConcurrentReindex'), instance_double('Gitlab::Database::Reindexing::ConcurrentReindex')] }

      it_behaves_like 'reindexing'
    end

    context 'single index' do
      subject { described_class.perform(indexes.first) }

      let(:indexes) { [instance_double('Gitlab::Database::PostgresIndex')] }
      let(:reindexers) { [instance_double('Gitlab::Database::Reindexing::ConcurrentReindex')] }

      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