summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration/steal_migrate_merge_request_diff_commit_users_spec.rb
blob: f2fb2ab6b6ed0cb0815928a55bb3aeab15c9f813 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::BackgroundMigration::StealMigrateMergeRequestDiffCommitUsers do
  let(:migration) { described_class.new }

  describe '#perform' do
    it 'processes the background migration' do
      spy = instance_spy(
        Gitlab::BackgroundMigration::MigrateMergeRequestDiffCommitUsers
      )

      allow(Gitlab::BackgroundMigration::MigrateMergeRequestDiffCommitUsers)
        .to receive(:new)
        .and_return(spy)

      expect(spy).to receive(:perform).with(1, 4)
      expect(migration).to receive(:schedule_next_job)

      migration.perform(1, 4)
    end
  end

  describe '#schedule_next_job' do
    it 'schedules the next job in ascending order' do
      Gitlab::Database::BackgroundMigrationJob.create!(
        class_name: 'MigrateMergeRequestDiffCommitUsers',
        arguments: [10, 20]
      )

      Gitlab::Database::BackgroundMigrationJob.create!(
        class_name: 'MigrateMergeRequestDiffCommitUsers',
        arguments: [40, 50]
      )

      expect(BackgroundMigrationWorker)
        .to receive(:perform_in)
        .with(5.minutes, 'StealMigrateMergeRequestDiffCommitUsers', [10, 20])

      migration.schedule_next_job
    end

    it 'does not schedule any new jobs when there are none' do
      expect(BackgroundMigrationWorker).not_to receive(:perform_in)

      migration.schedule_next_job
    end
  end
end