From fa3acb3bb662bef9d16a072f78d0048365a0f1dc Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 11 Jul 2017 15:19:57 +0200 Subject: Add pending set of specs for stage_id cleanup migration --- .../clean_stage_id_reference_migration_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 spec/migrations/clean_stage_id_reference_migration_spec.rb (limited to 'spec/migrations') diff --git a/spec/migrations/clean_stage_id_reference_migration_spec.rb b/spec/migrations/clean_stage_id_reference_migration_spec.rb new file mode 100644 index 00000000000..17be549ddd3 --- /dev/null +++ b/spec/migrations/clean_stage_id_reference_migration_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20170710083355_clean_stage_id_reference_migration.rb') + +describe CleanStageIdReferenceMigration, :migration, :sidekiq do + context 'when there are enqueued background migrations' do + pending 'processes enqueued jobs synchronously' do + fail + end + end + + context 'when there are scheduled background migrations' do + pending 'immediately processes scheduled jobs' do + fail + end + end + + context 'when there are no background migrations pending' do + pending 'does nothing' do + fail + end + end +end -- cgit v1.2.1 From 5c3fd67075782b0cf1ef81254e81ae21b38a2012 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 18 Jul 2017 10:31:22 +0200 Subject: Add specs for stage_id reference cleanup migration --- .../clean_stage_id_reference_migration_spec.rb | 29 ++++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'spec/migrations') diff --git a/spec/migrations/clean_stage_id_reference_migration_spec.rb b/spec/migrations/clean_stage_id_reference_migration_spec.rb index 17be549ddd3..0518c4de799 100644 --- a/spec/migrations/clean_stage_id_reference_migration_spec.rb +++ b/spec/migrations/clean_stage_id_reference_migration_spec.rb @@ -1,22 +1,29 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20170710083355_clean_stage_id_reference_migration.rb') -describe CleanStageIdReferenceMigration, :migration, :sidekiq do - context 'when there are enqueued background migrations' do - pending 'processes enqueued jobs synchronously' do - fail - end - end +describe CleanStageIdReferenceMigration, :migration, :sidekiq, :redis do + let(:migration) { MigrateStageIdReferenceInBackground::MIGRATION } + + context 'when there are pending background migrations' do + it 'processes enqueued jobs synchronously' do + Sidekiq::Testing.disable! do + BackgroundMigrationWorker.perform_in(2.minutes, migration, [1]) + BackgroundMigrationWorker.perform_async(migration, [1]) - context 'when there are scheduled background migrations' do - pending 'immediately processes scheduled jobs' do - fail + expect(Gitlab::BackgroundMigration).to receive(:perform).twice + + migrate! + end end end context 'when there are no background migrations pending' do - pending 'does nothing' do - fail + it 'does nothing' do + Sidekiq::Testing.disable! do + expect(Gitlab::BackgroundMigration).not_to receive(:perform) + + migrate! + end end end end -- cgit v1.2.1 From 73c7b968850b77dd2d740b494b4a98adb1222d41 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 18 Jul 2017 11:51:47 +0200 Subject: Remove migration dependency from stage_id migration --- spec/migrations/clean_stage_id_reference_migration_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec/migrations') diff --git a/spec/migrations/clean_stage_id_reference_migration_spec.rb b/spec/migrations/clean_stage_id_reference_migration_spec.rb index 0518c4de799..1b8d044ed61 100644 --- a/spec/migrations/clean_stage_id_reference_migration_spec.rb +++ b/spec/migrations/clean_stage_id_reference_migration_spec.rb @@ -1,11 +1,12 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20170710083355_clean_stage_id_reference_migration.rb') +require Rails.root.join('db', 'post_migrate', '20170628080858_migrate_stage_id_reference_in_background') describe CleanStageIdReferenceMigration, :migration, :sidekiq, :redis do let(:migration) { MigrateStageIdReferenceInBackground::MIGRATION } context 'when there are pending background migrations' do - it 'processes enqueued jobs synchronously' do + it 'processes pending jobs synchronously' do Sidekiq::Testing.disable! do BackgroundMigrationWorker.perform_in(2.minutes, migration, [1]) BackgroundMigrationWorker.perform_async(migration, [1]) -- cgit v1.2.1 From a6d1e92d98e71098c5a32999294bcdce6c7a092d Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 19 Jul 2017 13:19:27 +0200 Subject: Isolate stage_id reference clean up migration This addreses a review remarks discussed in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12785/diffs#note_35276344 --- spec/migrations/clean_stage_id_reference_migration_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/migrations') diff --git a/spec/migrations/clean_stage_id_reference_migration_spec.rb b/spec/migrations/clean_stage_id_reference_migration_spec.rb index 1b8d044ed61..c2072f2672d 100644 --- a/spec/migrations/clean_stage_id_reference_migration_spec.rb +++ b/spec/migrations/clean_stage_id_reference_migration_spec.rb @@ -1,17 +1,17 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20170710083355_clean_stage_id_reference_migration.rb') -require Rails.root.join('db', 'post_migrate', '20170628080858_migrate_stage_id_reference_in_background') describe CleanStageIdReferenceMigration, :migration, :sidekiq, :redis do - let(:migration) { MigrateStageIdReferenceInBackground::MIGRATION } + let(:migration) { 'MigrateBuildStageIdReference' } context 'when there are pending background migrations' do it 'processes pending jobs synchronously' do Sidekiq::Testing.disable! do - BackgroundMigrationWorker.perform_in(2.minutes, migration, [1]) - BackgroundMigrationWorker.perform_async(migration, [1]) + BackgroundMigrationWorker.perform_in(2.minutes, migration, [1, 1]) + BackgroundMigrationWorker.perform_async(migration, [1, 1]) - expect(Gitlab::BackgroundMigration).to receive(:perform).twice + expect(Gitlab::BackgroundMigration) + .to receive(:perform).twice.and_call_original migrate! end -- cgit v1.2.1 From 841de9752fb35b7d1a701da8764729ba334c2da5 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 20 Jul 2017 10:53:52 +0200 Subject: 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. --- .../clean_stage_id_reference_migration_spec.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'spec/migrations') diff --git a/spec/migrations/clean_stage_id_reference_migration_spec.rb b/spec/migrations/clean_stage_id_reference_migration_spec.rb index c2072f2672d..9a581df28a2 100644 --- a/spec/migrations/clean_stage_id_reference_migration_spec.rb +++ b/spec/migrations/clean_stage_id_reference_migration_spec.rb @@ -2,28 +2,32 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20170710083355_clean_stage_id_reference_migration.rb') 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 it 'processes pending jobs synchronously' do Sidekiq::Testing.disable! do - BackgroundMigrationWorker.perform_in(2.minutes, migration, [1, 1]) - BackgroundMigrationWorker.perform_async(migration, [1, 1]) - - expect(Gitlab::BackgroundMigration) - .to receive(:perform).twice.and_call_original + 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 - expect(Gitlab::BackgroundMigration).not_to receive(:perform) - migrate! + + expect(migration).not_to have_received(:perform) end end end -- cgit v1.2.1