2022-06-28 12:09:11 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require_migration!
|
|
|
|
|
2022-07-08 12:09:24 +00:00
|
|
|
RSpec.describe RescheduleBackfillImportedIssueSearchData do
|
|
|
|
let_it_be(:reschedule_migration) { described_class::MIGRATION }
|
2022-06-28 12:09:11 +00:00
|
|
|
|
2022-07-28 06:11:15 +00:00
|
|
|
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
|
2022-06-28 12:09:11 +00:00
|
|
|
reversible_migration do |migration|
|
|
|
|
migration.before -> {
|
2022-07-08 12:09:24 +00:00
|
|
|
expect(reschedule_migration).not_to have_scheduled_batched_migration
|
2022-06-28 12:09:11 +00:00
|
|
|
}
|
|
|
|
migration.after -> {
|
2022-07-08 12:09:24 +00:00
|
|
|
expect(reschedule_migration).to have_scheduled_batched_migration(
|
2022-06-28 12:09:11 +00:00
|
|
|
table_name: :issues,
|
|
|
|
column_name: :id,
|
|
|
|
interval: described_class::DELAY_INTERVAL,
|
2022-07-28 06:11:15 +00:00
|
|
|
batch_min_value: batch_min_value
|
2022-06-28 12:09:11 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-28 06:11:15 +00:00
|
|
|
context 'when BackfillIssueSearchData.max_value is nil' do
|
|
|
|
let(:batch_min_value) { described_class::BATCH_MIN_VALUE }
|
|
|
|
|
|
|
|
it_behaves_like 'backfill rescheduler'
|
|
|
|
end
|
|
|
|
|
2022-06-28 12:09:11 +00:00
|
|
|
context 'when BackfillIssueSearchData.max_value exists' do
|
2022-07-28 06:11:15 +00:00
|
|
|
let(:batch_min_value) { described_class::BATCH_MIN_VALUE }
|
|
|
|
|
2022-06-28 12:09:11 +00:00
|
|
|
before do
|
2022-07-28 06:11:15 +00:00
|
|
|
create_batched_migration(max_value: 200)
|
2022-06-28 12:09:11 +00:00
|
|
|
end
|
|
|
|
|
2022-07-28 06:11:15 +00:00
|
|
|
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'
|
2022-06-28 12:09:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|