2017-07-11 13:19:57 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require Rails.root.join('db', 'migrate', '20170710083355_clean_stage_id_reference_migration.rb')
|
|
|
|
|
2017-07-18 08:31:22 +00:00
|
|
|
describe CleanStageIdReferenceMigration, :migration, :sidekiq, :redis do
|
2017-07-20 08:53:52 +00:00
|
|
|
let(:migration_class) { 'MigrateBuildStageIdReference' }
|
|
|
|
let(:migration) { spy('migration') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(Gitlab::BackgroundMigration.const_get(migration_class))
|
|
|
|
.to receive(:new).and_return(migration)
|
|
|
|
end
|
2017-07-18 08:31:22 +00:00
|
|
|
|
|
|
|
context 'when there are pending background migrations' do
|
2017-07-18 09:51:47 +00:00
|
|
|
it 'processes pending jobs synchronously' do
|
2017-07-18 08:31:22 +00:00
|
|
|
Sidekiq::Testing.disable! do
|
2017-07-20 08:53:52 +00:00
|
|
|
BackgroundMigrationWorker.perform_in(2.minutes, migration_class, [1, 1])
|
|
|
|
BackgroundMigrationWorker.perform_async(migration_class, [1, 1])
|
2017-07-18 08:31:22 +00:00
|
|
|
|
|
|
|
migrate!
|
2017-07-20 08:53:52 +00:00
|
|
|
|
|
|
|
expect(migration).to have_received(:perform).with(1, 1).twice
|
2017-07-18 08:31:22 +00:00
|
|
|
end
|
2017-07-11 13:19:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
context 'when there are no background migrations pending' do
|
2017-07-18 08:31:22 +00:00
|
|
|
it 'does nothing' do
|
|
|
|
Sidekiq::Testing.disable! do
|
|
|
|
migrate!
|
2017-07-20 08:53:52 +00:00
|
|
|
|
|
|
|
expect(migration).not_to have_received(:perform)
|
2017-07-18 08:31:22 +00:00
|
|
|
end
|
2017-07-11 13:19:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|