diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-05-07 15:38:11 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-05-07 15:38:11 +0300 |
commit | cffb3e6805ae8b2b3ee909c7561953b1d99bc1ea (patch) | |
tree | 46284242dd5384dc064873fb2f8bd15905e297f7 /spec/migrations/cleanup_build_stage_migration_spec.rb | |
parent | 965d0394d371f427ad0423bda2a6dc8867b31563 (diff) |
Cleanup pipeline build stage background migration
Diffstat (limited to 'spec/migrations/cleanup_build_stage_migration_spec.rb')
-rw-r--r-- | spec/migrations/cleanup_build_stage_migration_spec.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/migrations/cleanup_build_stage_migration_spec.rb b/spec/migrations/cleanup_build_stage_migration_spec.rb new file mode 100644 index 00000000000..4d4d02aaa94 --- /dev/null +++ b/spec/migrations/cleanup_build_stage_migration_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20180420010616_cleanup_build_stage_migration.rb') + +describe CleanupBuildStageMigration, :migration, :sidekiq, :redis do + let(:migration) { spy('migration') } + + before do + allow(Gitlab::BackgroundMigration::MigrateBuildStage) + .to receive(:new).and_return(migration) + end + + context 'when there are pending background migrations' do + it 'processes pending jobs synchronously' do + Sidekiq::Testing.disable! do + BackgroundMigrationWorker + .perform_in(2.minutes, 'MigrateBuildStage', [1, 1]) + BackgroundMigrationWorker + .perform_async('MigrateBuildStage', [1, 1]) + + migrate! + + expect(migration).to have_received(:perform).with(1, 1).twice + end + end + end + + context 'when there are no background migrations pending' do + it 'does nothing' do + Sidekiq::Testing.disable! do + migrate! + + expect(migration).not_to have_received(:perform) + end + end + end + + context 'when there are still unmigrated builds present' do + let(:builds) { table('ci_builds') } + + before do + builds.create!(name: 'test:1', ref: 'master') + builds.create!(name: 'test:2', ref: 'master') + end + + it 'migrates stages sequentially in batches' do + expect(builds.all).to all(have_attributes(stage_id: nil)) + + migrate! + + expect(migration).to have_received(:perform).once + end + end +end |