summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration/merge_request_assignees_migration_progress_check_spec.rb
blob: 85a9c88ebff667a8735e4dc539de4c4e9cf10e62 (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
91
92
93
94
95
96
97
98
99
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::BackgroundMigration::MergeRequestAssigneesMigrationProgressCheck do
  context 'rescheduling' do
    context 'when there are ongoing and no dead jobs' do
      it 'reschedules check' do
        allow(Gitlab::BackgroundMigration).to receive(:exists?)
                                                .with('PopulateMergeRequestAssigneesTable')
                                                .and_return(true)

        allow(Gitlab::BackgroundMigration).to receive(:dead_jobs?)
                                                .with('PopulateMergeRequestAssigneesTable')
                                                .and_return(false)

        expect(BackgroundMigrationWorker).to receive(:perform_in).with(described_class::RESCHEDULE_DELAY, described_class.name)

        described_class.new.perform
      end
    end

    context 'when there are ongoing and dead jobs' do
      it 'reschedules check' do
        allow(Gitlab::BackgroundMigration).to receive(:exists?)
                                                .with('PopulateMergeRequestAssigneesTable')
                                                .and_return(true)

        allow(Gitlab::BackgroundMigration).to receive(:dead_jobs?)
                                                .with('PopulateMergeRequestAssigneesTable')
                                                .and_return(true)

        expect(BackgroundMigrationWorker).to receive(:perform_in).with(described_class::RESCHEDULE_DELAY, described_class.name)

        described_class.new.perform
      end
    end

    context 'when there retrying jobs and no scheduled' do
      it 'reschedules check' do
        allow(Gitlab::BackgroundMigration).to receive(:exists?)
                                                .with('PopulateMergeRequestAssigneesTable')
                                                .and_return(false)

        allow(Gitlab::BackgroundMigration).to receive(:retrying_jobs?)
                                                .with('PopulateMergeRequestAssigneesTable')
                                                .and_return(true)

        expect(BackgroundMigrationWorker).to receive(:perform_in).with(described_class::RESCHEDULE_DELAY, described_class.name)

        described_class.new.perform
      end
    end
  end

  context 'when there are no scheduled, or retrying or dead' do
    before do
      stub_feature_flags(multiple_merge_request_assignees: false)
    end

    it 'enables feature' do
      allow(Gitlab::BackgroundMigration).to receive(:exists?)
                                              .with('PopulateMergeRequestAssigneesTable')
                                              .and_return(false)

      allow(Gitlab::BackgroundMigration).to receive(:retrying_jobs?)
                                              .with('PopulateMergeRequestAssigneesTable')
                                              .and_return(false)

      allow(Gitlab::BackgroundMigration).to receive(:dead_jobs?)
                                              .with('PopulateMergeRequestAssigneesTable')
                                              .and_return(false)

      described_class.new.perform

      expect(Feature.enabled?(:multiple_merge_request_assignees, type: :licensed)).to eq(true)
    end
  end

  context 'when there are only dead jobs' do
    it 'raises DeadJobsError error' do
      allow(Gitlab::BackgroundMigration).to receive(:exists?)
                                              .with('PopulateMergeRequestAssigneesTable')
                                              .and_return(false)

      allow(Gitlab::BackgroundMigration).to receive(:retrying_jobs?)
                                              .with('PopulateMergeRequestAssigneesTable')
                                              .and_return(false)

      allow(Gitlab::BackgroundMigration).to receive(:dead_jobs?)
                                              .with('PopulateMergeRequestAssigneesTable')
                                              .and_return(true)

      expect { described_class.new.perform }
        .to raise_error(described_class::DeadJobsError,
                        "Only dead background jobs in the queue for #{described_class::WORKER}")
    end
  end
end