2019-02-11 12:48:37 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
2019-02-14 08:48:20 -05:00
|
|
|
require Rails.root.join('db', 'post_migrate', '20190214112022_schedule_sync_issuables_state_id.rb')
|
2019-02-11 12:48:37 -05:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe ScheduleSyncIssuablesStateId do
|
2019-02-11 12:48:37 -05:00
|
|
|
let(:namespaces) { table(:namespaces) }
|
|
|
|
let(:projects) { table(:projects) }
|
|
|
|
let(:merge_requests) { table(:merge_requests) }
|
|
|
|
let(:issues) { table(:issues) }
|
|
|
|
let(:migration) { described_class.new }
|
2019-03-28 10:31:14 -04:00
|
|
|
let(:group) { namespaces.create!(name: 'gitlab', path: 'gitlab') }
|
|
|
|
let(:project) { projects.create!(namespace_id: group.id) }
|
2019-02-11 12:48:37 -05:00
|
|
|
|
2019-02-19 09:33:30 -05:00
|
|
|
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
|
2020-08-31 11:10:41 -04:00
|
|
|
freeze_time do
|
2019-02-19 09:33:30 -05:00
|
|
|
migrate!
|
|
|
|
|
2019-03-01 14:24:47 -05:00
|
|
|
expect(migration).to be_scheduled_delayed_migration(120.seconds, resource_1.id, resource_2.id)
|
|
|
|
expect(migration).to be_scheduled_delayed_migration(240.seconds, resource_3.id, resource_4.id)
|
2019-02-19 09:33:30 -05:00
|
|
|
expect(BackgroundMigrationWorker.jobs.size).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-11 12:48:37 -05:00
|
|
|
describe '#up' do
|
|
|
|
context 'issues' do
|
2019-10-23 05:06:03 -04:00
|
|
|
it 'migrates state column to integer', :sidekiq_might_not_need_inline do
|
2019-02-11 12:48:37 -05:00
|
|
|
opened_issue = issues.create!(description: 'first', state: 'opened')
|
|
|
|
closed_issue = issues.create!(description: 'second', state: 'closed')
|
2019-02-12 11:40:37 -05:00
|
|
|
invalid_state_issue = issues.create!(description: 'fourth', state: 'not valid')
|
2019-02-11 12:48:37 -05:00
|
|
|
|
|
|
|
migrate!
|
|
|
|
|
2019-02-14 08:48:20 -05:00
|
|
|
expect(opened_issue.reload.state_id).to eq(Issue.available_states[:opened])
|
|
|
|
expect(closed_issue.reload.state_id).to eq(Issue.available_states[:closed])
|
2019-02-12 11:40:37 -05:00
|
|
|
expect(invalid_state_issue.reload.state_id).to be_nil
|
2019-02-11 12:48:37 -05:00
|
|
|
end
|
2019-02-18 15:43:16 -05:00
|
|
|
|
2019-02-19 09:33:30 -05:00
|
|
|
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
|
2019-02-11 12:48:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'merge requests' do
|
2019-10-23 05:06:03 -04:00
|
|
|
it 'migrates state column to integer', :sidekiq_might_not_need_inline do
|
2019-03-28 10:31:14 -04:00
|
|
|
opened_merge_request = merge_requests.create!(state: 'opened', target_project_id: project.id, target_branch: 'feature1', source_branch: 'master')
|
|
|
|
closed_merge_request = merge_requests.create!(state: 'closed', target_project_id: project.id, target_branch: 'feature2', source_branch: 'master')
|
|
|
|
merged_merge_request = merge_requests.create!(state: 'merged', target_project_id: project.id, target_branch: 'feature3', source_branch: 'master')
|
|
|
|
locked_merge_request = merge_requests.create!(state: 'locked', target_project_id: project.id, target_branch: 'feature4', source_branch: 'master')
|
2019-02-11 12:48:37 -05:00
|
|
|
|
|
|
|
migrate!
|
|
|
|
|
2019-02-14 08:48:20 -05:00
|
|
|
expect(opened_merge_request.reload.state_id).to eq(MergeRequest.available_states[:opened])
|
|
|
|
expect(closed_merge_request.reload.state_id).to eq(MergeRequest.available_states[:closed])
|
|
|
|
expect(merged_merge_request.reload.state_id).to eq(MergeRequest.available_states[:merged])
|
|
|
|
expect(locked_merge_request.reload.state_id).to eq(MergeRequest.available_states[:locked])
|
2019-02-11 12:48:37 -05:00
|
|
|
end
|
2019-02-18 15:43:16 -05:00
|
|
|
|
2019-02-19 09:33:30 -05:00
|
|
|
it_behaves_like 'scheduling migrations' do
|
|
|
|
let(:migration) { described_class::MERGE_REQUESTS_MIGRATION }
|
2019-03-28 10:31:14 -04:00
|
|
|
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') }
|
2019-02-19 09:33:30 -05:00
|
|
|
end
|
2019-02-11 12:48:37 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|