BigW Consortium Gitlab

Commit 001dd56e by Yorick Peterse

Merge branch 'backstage/gb/build-stage-id-ref-bg-migration-cleanup' into 'master'

Implement build stage_id reference migration clean up Closes #34893 See merge request !12785
parents 652b2d0d 841de975
class CleanStageIdReferenceMigration < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
##
# `MigrateStageIdReferenceInBackground` background migration cleanup.
#
def up
Gitlab::BackgroundMigration.steal('MigrateBuildStageIdReference')
end
def down
# noop
end
end
......@@ -26,7 +26,7 @@ module Gitlab
next unless migration_class == steal_class
begin
perform(migration_class, migration_args, retries: 3) if job.delete
perform(migration_class, migration_args) if job.delete
rescue Exception # rubocop:disable Lint/RescueException
BackgroundMigrationWorker # enqueue this migration again
.perform_async(migration_class, migration_args)
......
......@@ -25,7 +25,7 @@ describe Gitlab::BackgroundMigration do
expect(queue[0]).to receive(:delete).and_return(true)
expect(described_class).to receive(:perform)
.with('Foo', [10, 20], anything)
.with('Foo', [10, 20])
described_class.steal('Foo')
end
......@@ -93,9 +93,9 @@ describe Gitlab::BackgroundMigration do
it 'steals from the scheduled sets queue first' do
Sidekiq::Testing.disable! do
expect(described_class).to receive(:perform)
.with('Object', [1], anything).ordered
.with('Object', [1]).ordered
expect(described_class).to receive(:perform)
.with('Object', [2], anything).ordered
.with('Object', [2]).ordered
BackgroundMigrationWorker.perform_async('Object', [2])
BackgroundMigrationWorker.perform_in(10.minutes, 'Object', [1])
......
require 'spec_helper'
require Rails.root.join('db', 'migrate', '20170710083355_clean_stage_id_reference_migration.rb')
describe CleanStageIdReferenceMigration, :migration, :sidekiq, :redis do
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
it 'processes pending jobs synchronously' do
Sidekiq::Testing.disable! do
BackgroundMigrationWorker.perform_in(2.minutes, migration_class, [1, 1])
BackgroundMigrationWorker.perform_async(migration_class, [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
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