Commit 841de975 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Fix background migration cleanup specs

We need to use a spy because an `after` RSpec hook is also going to call
the migration we want to test, so we need to use `have_received`
expectation. See gitlab-org/gitlab-ce#35351 for more details.
parent 98f5c00e
...@@ -2,28 +2,32 @@ require 'spec_helper' ...@@ -2,28 +2,32 @@ require 'spec_helper'
require Rails.root.join('db', 'migrate', '20170710083355_clean_stage_id_reference_migration.rb') require Rails.root.join('db', 'migrate', '20170710083355_clean_stage_id_reference_migration.rb')
describe CleanStageIdReferenceMigration, :migration, :sidekiq, :redis do describe CleanStageIdReferenceMigration, :migration, :sidekiq, :redis do
let(:migration) { 'MigrateBuildStageIdReference' } let(:migration_class) { 'MigrateBuildStageIdReference' }
let(:migration) { spy('migration') }
before do
allow(Gitlab::BackgroundMigration.const_get(migration_class))
.to receive(:new).and_return(migration)
end
context 'when there are pending background migrations' do context 'when there are pending background migrations' do
it 'processes pending jobs synchronously' do it 'processes pending jobs synchronously' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
BackgroundMigrationWorker.perform_in(2.minutes, migration, [1, 1]) BackgroundMigrationWorker.perform_in(2.minutes, migration_class, [1, 1])
BackgroundMigrationWorker.perform_async(migration, [1, 1]) BackgroundMigrationWorker.perform_async(migration_class, [1, 1])
expect(Gitlab::BackgroundMigration)
.to receive(:perform).twice.and_call_original
migrate! migrate!
expect(migration).to have_received(:perform).with(1, 1).twice
end end
end end
end end
context 'when there are no background migrations pending' do context 'when there are no background migrations pending' do
it 'does nothing' do it 'does nothing' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
expect(Gitlab::BackgroundMigration).not_to receive(:perform)
migrate! migrate!
expect(migration).not_to have_received(:perform)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment