diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-01 13:38:24 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-01 13:38:24 +0000 |
commit | 0396082c12f518f48e136968dbf0b4e5f774641c (patch) | |
tree | 9ee22b3f2d65483c316d30397b7e065d4dec5fec /spec/migrations/reschedule_backfill_imported_issue_search_data_spec.rb | |
parent | cb7e80d1211dae947e40290a834cbe29ee36364e (diff) | |
download | gitlab-ce-0396082c12f518f48e136968dbf0b4e5f774641c.tar.gz |
Add latest changes from gitlab-org/gitlab@15-2-stable-ee
Diffstat (limited to 'spec/migrations/reschedule_backfill_imported_issue_search_data_spec.rb')
-rw-r--r-- | spec/migrations/reschedule_backfill_imported_issue_search_data_spec.rb | 85 |
1 files changed, 60 insertions, 25 deletions
diff --git a/spec/migrations/reschedule_backfill_imported_issue_search_data_spec.rb b/spec/migrations/reschedule_backfill_imported_issue_search_data_spec.rb index 7d1377bbeba..7581c201a59 100644 --- a/spec/migrations/reschedule_backfill_imported_issue_search_data_spec.rb +++ b/spec/migrations/reschedule_backfill_imported_issue_search_data_spec.rb @@ -6,8 +6,22 @@ require_migration! RSpec.describe RescheduleBackfillImportedIssueSearchData do let_it_be(:reschedule_migration) { described_class::MIGRATION } - context 'when BackfillIssueSearchData.max_value is nil' do - it 'schedules a new batched migration with a default value' do + 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 @@ -17,39 +31,60 @@ RSpec.describe RescheduleBackfillImportedIssueSearchData do table_name: :issues, column_name: :id, interval: described_class::DELAY_INTERVAL, - batch_min_value: described_class::BATCH_MIN_VALUE + 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 - Gitlab::Database::BackgroundMigration::BatchedMigration - .create!( - max_value: 200, - batch_size: 200, - sub_batch_size: 20, - interval: 120, - job_class_name: 'BackfillIssueSearchData', - table_name: 'issues', - column_name: 'id', - gitlab_schema: 'glschema' - ) + create_batched_migration(max_value: 200) end - it 'schedules a new batched migration with a custom max_value' do - reversible_migration do |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: 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 |