diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-10 12:10:09 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-10 12:10:09 +0000 |
commit | c68905777ea271aea120a58d2d1246e84aea4264 (patch) | |
tree | 55064d8892d91fe0cad6c29a5e042778b1f23c68 /spec/migrations | |
parent | 67b0b1c43f3d705b92f62ef231dfce1d7f3c0a30 (diff) | |
download | gitlab-ce-c68905777ea271aea120a58d2d1246e84aea4264.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/retry_backfill_traversal_ids_spec.rb | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/spec/migrations/retry_backfill_traversal_ids_spec.rb b/spec/migrations/retry_backfill_traversal_ids_spec.rb new file mode 100644 index 00000000000..e5ebd4228ca --- /dev/null +++ b/spec/migrations/retry_backfill_traversal_ids_spec.rb @@ -0,0 +1,93 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20210604070207_retry_backfill_traversal_ids.rb') + +RSpec.describe RetryBackfillTraversalIds, :migration do + include ReloadHelpers + + let_it_be(:namespaces_table) { table(:namespaces) } + + context 'when BackfillNamespaceTraversalIdsRoots jobs are pending' do + before do + table(:background_migration_jobs).create!( + class_name: 'BackfillNamespaceTraversalIdsRoots', + arguments: [1, 4, 100], + status: Gitlab::Database::BackgroundMigrationJob.statuses['pending'] + ) + table(:background_migration_jobs).create!( + class_name: 'BackfillNamespaceTraversalIdsRoots', + arguments: [5, 9, 100], + status: Gitlab::Database::BackgroundMigrationJob.statuses['succeeded'] + ) + end + + it 'queues pending jobs' do + migrate! + + expect(BackgroundMigrationWorker.jobs.length).to eq(1) + expect(BackgroundMigrationWorker.jobs[0]['args']).to eq(['BackfillNamespaceTraversalIdsRoots', [1, 4, 100]]) + expect(BackgroundMigrationWorker.jobs[0]['at']).to be_nil + end + end + + context 'when BackfillNamespaceTraversalIdsChildren jobs are pending' do + before do + table(:background_migration_jobs).create!( + class_name: 'BackfillNamespaceTraversalIdsChildren', + arguments: [1, 4, 100], + status: Gitlab::Database::BackgroundMigrationJob.statuses['pending'] + ) + table(:background_migration_jobs).create!( + class_name: 'BackfillNamespaceTraversalIdsRoots', + arguments: [5, 9, 100], + status: Gitlab::Database::BackgroundMigrationJob.statuses['succeeded'] + ) + end + + it 'queues pending jobs' do + migrate! + + expect(BackgroundMigrationWorker.jobs.length).to eq(1) + expect(BackgroundMigrationWorker.jobs[0]['args']).to eq(['BackfillNamespaceTraversalIdsChildren', [1, 4, 100]]) + expect(BackgroundMigrationWorker.jobs[0]['at']).to be_nil + end + end + + context 'when BackfillNamespaceTraversalIdsRoots and BackfillNamespaceTraversalIdsChildren jobs are pending' do + before do + table(:background_migration_jobs).create!( + class_name: 'BackfillNamespaceTraversalIdsRoots', + arguments: [1, 4, 100], + status: Gitlab::Database::BackgroundMigrationJob.statuses['pending'] + ) + table(:background_migration_jobs).create!( + class_name: 'BackfillNamespaceTraversalIdsChildren', + arguments: [5, 9, 100], + status: Gitlab::Database::BackgroundMigrationJob.statuses['pending'] + ) + table(:background_migration_jobs).create!( + class_name: 'BackfillNamespaceTraversalIdsRoots', + arguments: [11, 14, 100], + status: Gitlab::Database::BackgroundMigrationJob.statuses['succeeded'] + ) + table(:background_migration_jobs).create!( + class_name: 'BackfillNamespaceTraversalIdsChildren', + arguments: [15, 19, 100], + status: Gitlab::Database::BackgroundMigrationJob.statuses['succeeded'] + ) + end + + it 'queues pending jobs' do + freeze_time do + migrate! + + expect(BackgroundMigrationWorker.jobs.length).to eq(2) + expect(BackgroundMigrationWorker.jobs[0]['args']).to eq(['BackfillNamespaceTraversalIdsRoots', [1, 4, 100]]) + expect(BackgroundMigrationWorker.jobs[0]['at']).to be_nil + expect(BackgroundMigrationWorker.jobs[1]['args']).to eq(['BackfillNamespaceTraversalIdsChildren', [5, 9, 100]]) + expect(BackgroundMigrationWorker.jobs[1]['at']).to eq(RetryBackfillTraversalIds::DELAY_INTERVAL.from_now.to_f) + end + end + end +end |