diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-05 19:40:33 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-05 19:40:33 +0000 |
commit | d7c5be92af9c10cf20e78363c188c1a707a6bb90 (patch) | |
tree | df2d354bc4277c7a0324fb8240bd4e24d58007f2 /spec/migrations | |
parent | b28d1361dd1ec63053dbfae475097928c6d01116 (diff) | |
download | gitlab-ce-d7c5be92af9c10cf20e78363c188c1a707a6bb90.tar.gz |
Add latest changes from gitlab-org/gitlab@15-6-stable-ee
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/20221002234454_finalize_group_member_namespace_id_migration_spec.rb | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/spec/migrations/20221002234454_finalize_group_member_namespace_id_migration_spec.rb b/spec/migrations/20221002234454_finalize_group_member_namespace_id_migration_spec.rb new file mode 100644 index 00000000000..9c27005065d --- /dev/null +++ b/spec/migrations/20221002234454_finalize_group_member_namespace_id_migration_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe FinalizeGroupMemberNamespaceIdMigration, :migration do + let(:batched_migrations) { table(:batched_background_migrations) } + + let_it_be(:migration) { described_class::MIGRATION } + + describe '#up' do + shared_examples 'finalizes the migration' do + it 'finalizes the migration' do + allow_next_instance_of(Gitlab::Database::BackgroundMigration::BatchedMigrationRunner) do |runner| + expect(runner).to receive(:finalize).with('BackfillMemberNamespaceForGroupMembers', :members, :id, []) + end + end + end + + context 'when migration is missing' do + it 'warns migration not found' do + expect(Gitlab::AppLogger) + .to receive(:warn).with(/Could not find batched background migration for the given configuration:/) + + migrate! + end + end + + context 'with migration present' do + let!(:group_member_namespace_id_backfill) do + batched_migrations.create!( + job_class_name: 'BackfillMemberNamespaceForGroupMembers', + table_name: :members, + column_name: :id, + job_arguments: [], + interval: 2.minutes, + min_value: 1, + max_value: 2, + batch_size: 1000, + sub_batch_size: 200, + gitlab_schema: :gitlab_main, + status: 3 # finished + ) + end + + context 'when migration finished successfully' do + it 'does not raise exception' do + expect { migrate! }.not_to raise_error + end + end + + context 'with different migration statuses' do + using RSpec::Parameterized::TableSyntax + + where(:status, :description) do + 0 | 'paused' + 1 | 'active' + 4 | 'failed' + 5 | 'finalizing' + end + + with_them do + before do + group_member_namespace_id_backfill.update!(status: status) + end + + it_behaves_like 'finalizes the migration' + end + end + end + end +end |