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

reschedule_backfill_imported_issue_search_data_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7581c201a59828cc629dc9ee55c17791ea4e27c2 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# frozen_string_literal: true

require 'spec_helper'
require_migration!

RSpec.describe RescheduleBackfillImportedIssueSearchData do
  let_it_be(:reschedule_migration) { described_class::MIGRATION }

  def create_batched_migration(max_value:)
    Gitlab::Database::BackgroundMigration::BatchedMigration
      .create!(
        max_value: max_value,
        batch_size: 200,
        sub_batch_size: 20,
        interval: 120,
        job_class_name: 'BackfillIssueSearchData',
        table_name: 'issues',
        column_name: 'id',
        gitlab_schema: 'glschema'
      )
  end

  shared_examples 'backfill rescheduler' do
    it 'schedules a new batched migration' do
      reversible_migration do |migration|
        migration.before -> {
          expect(reschedule_migration).not_to have_scheduled_batched_migration
        }
        migration.after -> {
          expect(reschedule_migration).to have_scheduled_batched_migration(
            table_name: :issues,
            column_name: :id,
            interval: described_class::DELAY_INTERVAL,
            batch_min_value: batch_min_value
          )
        }
      end
    end
  end

  context 'when BackfillIssueSearchData.max_value is nil' do
    let(:batch_min_value) { described_class::BATCH_MIN_VALUE }

    it_behaves_like 'backfill rescheduler'
  end

  context 'when BackfillIssueSearchData.max_value exists' do
    let(:batch_min_value) { described_class::BATCH_MIN_VALUE }

    before do
      create_batched_migration(max_value: 200)
    end

    it_behaves_like 'backfill rescheduler'
  end

  context 'when an issue is available' do
    let_it_be(:namespaces_table) { table(:namespaces) }
    let_it_be(:projects_table) { table(:projects) }

    let(:namespace) { namespaces_table.create!(name: 'gitlab-org', path: 'gitlab-org') }
    let(:project) { projects_table.create!(name: 'gitlab', path: 'gitlab-org/gitlab-ce', namespace_id: namespace.id, project_namespace_id: namespace.id) } # rubocop:disable Layout/LineLength
    let(:issue) { table(:issues).create!(project_id: project.id, title: 'test title', description: 'test description') }

    before do
      create_batched_migration(max_value: max_value)
    end

    context 'when BackfillIssueSearchData.max_value = Issue.maximum(:id)' do
      let(:max_value) { issue.id }
      let(:batch_min_value) { max_value }

      it_behaves_like 'backfill rescheduler'
    end

    context 'when BackfillIssueSearchData.max_value > Issue.maximum(:id)' do
      let(:max_value) { issue.id + 1 }
      let(:batch_min_value) { issue.id }

      it_behaves_like 'backfill rescheduler'
    end

    context 'when BackfillIssueSearchData.max_value < Issue.maximum(:id)' do
      let(:max_value) { issue.id - 1 }
      let(:batch_min_value) { max_value }

      it_behaves_like 'backfill rescheduler'
    end
  end
end