diff options
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/schedule_sync_issuables_state_id_spec.rb | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/spec/migrations/schedule_sync_issuables_state_id_spec.rb b/spec/migrations/schedule_sync_issuables_state_id_spec.rb index a746fb68c30..6c4c31ae554 100644 --- a/spec/migrations/schedule_sync_issuables_state_id_spec.rb +++ b/spec/migrations/schedule_sync_issuables_state_id_spec.rb @@ -15,6 +15,25 @@ describe ScheduleSyncIssuablesStateId, :migration do @project = projects.create!(namespace_id: @group.id) end + shared_examples 'scheduling migrations' do + before do + Sidekiq::Worker.clear_all + stub_const("#{described_class.name}::BATCH_SIZE", 2) + end + + it 'correctly schedules issuable sync background migration' do + Sidekiq::Testing.fake! do + Timecop.freeze do + migrate! + + expect(migration).to be_scheduled_delayed_migration(5.minutes, resource_1.id, resource_2.id) + expect(migration).to be_scheduled_delayed_migration(10.minutes, resource_3.id, resource_4.id) + expect(BackgroundMigrationWorker.jobs.size).to eq(2) + end + end + end + end + shared_examples 'rescheduling migrations' do before do Sidekiq::Worker.clear_all @@ -35,20 +54,6 @@ describe ScheduleSyncIssuablesStateId, :migration do end describe '#up' do - # it 'correctly schedules diff file deletion workers' do - # Sidekiq::Testing.fake! do - # Timecop.freeze do - # described_class.new.perform - - # expect(described_class::MIGRATION).to be_scheduled_delayed_migration(5.minutes, [1, 4, 5]) - - # expect(described_class::MIGRATION).to be_scheduled_delayed_migration(10.minutes, [6]) - - # expect(BackgroundMigrationWorker.jobs.size).to eq(2) - # end - # end - # end - context 'issues' do it 'migrates state column to integer' do opened_issue = issues.create!(description: 'first', state: 'opened') @@ -64,10 +69,18 @@ describe ScheduleSyncIssuablesStateId, :migration do expect(nil_state_issue.reload.state_id).to be_nil end + it_behaves_like 'scheduling migrations' do + let(:migration) { described_class::ISSUES_MIGRATION } + let!(:resource_1) { issues.create!(description: 'first', state: 'opened') } + let!(:resource_2) { issues.create!(description: 'second', state: 'closed') } + let!(:resource_3) { issues.create!(description: 'third', state: 'closed') } + let!(:resource_4) { issues.create!(description: 'fourth', state: 'closed') } + end + it_behaves_like 'rescheduling migrations' do let(:worker_class) { Gitlab::BackgroundMigration::SyncIssuesStateId } - let(:resource_1) { issues.create!(description: 'first', state: 'opened') } - let(:resource_2) { issues.create!(description: 'second', state: 'closed') } + let!(:resource_1) { issues.create!(description: 'first', state: 'opened') } + let!(:resource_2) { issues.create!(description: 'second', state: 'closed') } end end @@ -88,6 +101,14 @@ describe ScheduleSyncIssuablesStateId, :migration do expect(invalid_state_merge_request.reload.state_id).to be_nil end + it_behaves_like 'scheduling migrations' do + let(:migration) { described_class::MERGE_REQUESTS_MIGRATION } + let!(:resource_1) { merge_requests.create!(state: 'opened', target_project_id: @project.id, target_branch: 'feature1', source_branch: 'master') } + let!(:resource_2) { merge_requests.create!(state: 'closed', target_project_id: @project.id, target_branch: 'feature2', source_branch: 'master') } + let!(:resource_3) { merge_requests.create!(state: 'merged', target_project_id: @project.id, target_branch: 'feature3', source_branch: 'master') } + let!(:resource_4) { merge_requests.create!(state: 'locked', target_project_id: @project.id, target_branch: 'feature4', source_branch: 'master') } + end + it_behaves_like 'rescheduling migrations' do let(:worker_class) { Gitlab::BackgroundMigration::SyncMergeRequestsStateId } let(:resource_1) { merge_requests.create!(state: 'opened', target_project_id: @project.id, target_branch: 'feature1', source_branch: 'master') } |