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
|
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe SliceMergeRequestDiffCommitMigrations, :migration do
let(:migration) { described_class.new }
describe '#up' do
context 'when there are no jobs to process' do
it 'does nothing' do
expect(migration).not_to receive(:migrate_in)
expect(Gitlab::Database::BackgroundMigrationJob).not_to receive(:create!)
migration.up
end
end
context 'when there are pending jobs' do
let!(:job1) do
Gitlab::Database::BackgroundMigrationJob.create!(
class_name: described_class::MIGRATION_CLASS,
arguments: [1, 10_001]
)
end
let!(:job2) do
Gitlab::Database::BackgroundMigrationJob.create!(
class_name: described_class::MIGRATION_CLASS,
arguments: [10_001, 20_001]
)
end
it 'marks the old jobs as finished' do
migration.up
job1.reload
job2.reload
expect(job1).to be_succeeded
expect(job2).to be_succeeded
end
it 'the jobs are slices into smaller ranges' do
migration.up
new_jobs = Gitlab::Database::BackgroundMigrationJob
.for_migration_class(described_class::MIGRATION_CLASS)
.pending
.to_a
expect(new_jobs.map(&:arguments)).to eq([
[1, 5_001],
[5_001, 10_001],
[10_001, 15_001],
[15_001, 20_001]
])
end
it 'schedules a background migration for the first job' do
expect(migration)
.to receive(:migrate_in)
.with(1.hour, described_class::STEAL_MIGRATION_CLASS, [1, 5_001])
migration.up
end
end
end
end
|