diff options
author | Jarka Kadlecová <jarka@gitlab.com> | 2018-01-05 10:15:03 +0100 |
---|---|---|
committer | Jarka Kadlecová <jarka@gitlab.com> | 2018-01-05 13:40:31 +0100 |
commit | 153ea1830153b7d7c3be5ac2e7ca60486c9b2700 (patch) | |
tree | fe7010401e568032637b0c5c37c49eeb8d7226fc /spec | |
parent | 304851dc90c06d770042bf3cb0af887b6f3497e4 (diff) | |
download | gitlab-ce-153ea1830153b7d7c3be5ac2e7ca60486c9b2700.tar.gz |
Refactor matchers for background migrationsce-backport=reorder-issues
Diffstat (limited to 'spec')
10 files changed, 32 insertions, 54 deletions
diff --git a/spec/lib/gitlab/background_migration/prepare_untracked_uploads_spec.rb b/spec/lib/gitlab/background_migration/prepare_untracked_uploads_spec.rb index cd3f1a45270..8bb9ebe0419 100644 --- a/spec/lib/gitlab/background_migration/prepare_untracked_uploads_spec.rb +++ b/spec/lib/gitlab/background_migration/prepare_untracked_uploads_spec.rb @@ -2,21 +2,10 @@ require 'spec_helper' describe Gitlab::BackgroundMigration::PrepareUntrackedUploads, :sidekiq do include TrackUntrackedUploadsHelpers + include MigrationsHelpers let!(:untracked_files_for_uploads) { described_class::UntrackedFile } - matcher :be_scheduled_migration do |*expected| - match do |migration| - BackgroundMigrationWorker.jobs.any? do |job| - job['args'] == [migration, expected] - end - end - - failure_message do |migration| - "Migration `#{migration}` with args `#{expected.inspect}` not scheduled!" - end - end - before do DatabaseCleaner.clean diff --git a/spec/migrations/migrate_stage_id_reference_in_background_spec.rb b/spec/migrations/migrate_stage_id_reference_in_background_spec.rb index 9b92f4b70b0..a837498e1b1 100644 --- a/spec/migrations/migrate_stage_id_reference_in_background_spec.rb +++ b/spec/migrations/migrate_stage_id_reference_in_background_spec.rb @@ -35,9 +35,9 @@ describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do Timecop.freeze do migrate! - expect(described_class::MIGRATION).to be_scheduled_migration(2.minutes, 1, 2) - expect(described_class::MIGRATION).to be_scheduled_migration(2.minutes, 3, 3) - expect(described_class::MIGRATION).to be_scheduled_migration(4.minutes, 4, 5) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(2.minutes, 1, 2) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(2.minutes, 3, 3) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(4.minutes, 4, 5) expect(BackgroundMigrationWorker.jobs.size).to eq 3 end end diff --git a/spec/migrations/migrate_stages_statuses_spec.rb b/spec/migrations/migrate_stages_statuses_spec.rb index 094c9bc604e..79d2708f9ad 100644 --- a/spec/migrations/migrate_stages_statuses_spec.rb +++ b/spec/migrations/migrate_stages_statuses_spec.rb @@ -50,9 +50,9 @@ describe MigrateStagesStatuses, :migration do Timecop.freeze do migrate! - expect(described_class::MIGRATION).to be_scheduled_migration(5.minutes, 1, 1) - expect(described_class::MIGRATION).to be_scheduled_migration(5.minutes, 2, 2) - expect(described_class::MIGRATION).to be_scheduled_migration(10.minutes, 3, 3) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(5.minutes, 1, 1) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(5.minutes, 2, 2) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(10.minutes, 3, 3) expect(BackgroundMigrationWorker.jobs.size).to eq 3 end end diff --git a/spec/migrations/schedule_create_gpg_key_subkeys_from_gpg_keys_spec.rb b/spec/migrations/schedule_create_gpg_key_subkeys_from_gpg_keys_spec.rb index 0e884a7d910..65ec07da31c 100644 --- a/spec/migrations/schedule_create_gpg_key_subkeys_from_gpg_keys_spec.rb +++ b/spec/migrations/schedule_create_gpg_key_subkeys_from_gpg_keys_spec.rb @@ -2,18 +2,6 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20171005130944_schedule_create_gpg_key_subkeys_from_gpg_keys') describe ScheduleCreateGpgKeySubkeysFromGpgKeys, :migration, :sidekiq do - matcher :be_scheduled_migration do |*expected| - match do |migration| - BackgroundMigrationWorker.jobs.any? do |job| - job['args'] == [migration, expected] - end - end - - failure_message do |migration| - "Migration `#{migration}` with args `#{expected.inspect}` not scheduled!" - end - end - before do create(:gpg_key, id: 1, key: GpgHelpers::User1.public_key) create(:gpg_key, id: 2, key: GpgHelpers::User3.public_key) diff --git a/spec/migrations/schedule_merge_request_diff_migrations_spec.rb b/spec/migrations/schedule_merge_request_diff_migrations_spec.rb index 76afb6c19cf..d230f064444 100644 --- a/spec/migrations/schedule_merge_request_diff_migrations_spec.rb +++ b/spec/migrations/schedule_merge_request_diff_migrations_spec.rb @@ -24,9 +24,9 @@ describe ScheduleMergeRequestDiffMigrations, :migration, :sidekiq do Timecop.freeze do migrate! - expect(described_class::MIGRATION).to be_scheduled_migration(5.minutes, 1, 1) - expect(described_class::MIGRATION).to be_scheduled_migration(10.minutes, 2, 2) - expect(described_class::MIGRATION).to be_scheduled_migration(15.minutes, 4, 4) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(5.minutes, 1, 1) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(10.minutes, 2, 2) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(15.minutes, 4, 4) expect(BackgroundMigrationWorker.jobs.size).to eq 3 end end diff --git a/spec/migrations/schedule_merge_request_diff_migrations_take_two_spec.rb b/spec/migrations/schedule_merge_request_diff_migrations_take_two_spec.rb index cf323973384..1aab4ae1650 100644 --- a/spec/migrations/schedule_merge_request_diff_migrations_take_two_spec.rb +++ b/spec/migrations/schedule_merge_request_diff_migrations_take_two_spec.rb @@ -24,9 +24,9 @@ describe ScheduleMergeRequestDiffMigrationsTakeTwo, :migration, :sidekiq do Timecop.freeze do migrate! - expect(described_class::MIGRATION).to be_scheduled_migration(10.minutes, 1, 1) - expect(described_class::MIGRATION).to be_scheduled_migration(20.minutes, 2, 2) - expect(described_class::MIGRATION).to be_scheduled_migration(30.minutes, 4, 4) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(10.minutes, 1, 1) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(20.minutes, 2, 2) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(30.minutes, 4, 4) expect(BackgroundMigrationWorker.jobs.size).to eq 3 end end diff --git a/spec/migrations/schedule_merge_request_latest_merge_request_diff_id_migrations_spec.rb b/spec/migrations/schedule_merge_request_latest_merge_request_diff_id_migrations_spec.rb index 158d0bc02ed..c9fdbe95d13 100644 --- a/spec/migrations/schedule_merge_request_latest_merge_request_diff_id_migrations_spec.rb +++ b/spec/migrations/schedule_merge_request_latest_merge_request_diff_id_migrations_spec.rb @@ -44,9 +44,9 @@ describe ScheduleMergeRequestLatestMergeRequestDiffIdMigrations, :migration, :si Timecop.freeze do migrate! - expect(described_class::MIGRATION).to be_scheduled_migration(5.minutes, merge_request_1.id, merge_request_1.id) - expect(described_class::MIGRATION).to be_scheduled_migration(10.minutes, merge_request_2.id, merge_request_2.id) - expect(described_class::MIGRATION).to be_scheduled_migration(15.minutes, merge_request_4.id, merge_request_4.id) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(5.minutes, merge_request_1.id, merge_request_1.id) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(10.minutes, merge_request_2.id, merge_request_2.id) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(15.minutes, merge_request_4.id, merge_request_4.id) expect(BackgroundMigrationWorker.jobs.size).to eq 3 end end diff --git a/spec/migrations/schedule_populate_merge_request_metrics_with_events_data_spec.rb b/spec/migrations/schedule_populate_merge_request_metrics_with_events_data_spec.rb index 97e089c5cb8..2e6b2cff0ab 100644 --- a/spec/migrations/schedule_populate_merge_request_metrics_with_events_data_spec.rb +++ b/spec/migrations/schedule_populate_merge_request_metrics_with_events_data_spec.rb @@ -12,10 +12,10 @@ describe SchedulePopulateMergeRequestMetricsWithEventsData, :migration, :sidekiq migrate! expect(described_class::MIGRATION) - .to be_scheduled_migration(10.minutes, mrs.first.id, mrs.second.id) + .to be_scheduled_delayed_migration(10.minutes, mrs.first.id, mrs.second.id) expect(described_class::MIGRATION) - .to be_scheduled_migration(20.minutes, mrs.third.id, mrs.third.id) + .to be_scheduled_delayed_migration(20.minutes, mrs.third.id, mrs.third.id) expect(BackgroundMigrationWorker.jobs.size).to eq(2) end diff --git a/spec/migrations/track_untracked_uploads_spec.rb b/spec/migrations/track_untracked_uploads_spec.rb index 7fe7a140e2f..fe4d5b8a279 100644 --- a/spec/migrations/track_untracked_uploads_spec.rb +++ b/spec/migrations/track_untracked_uploads_spec.rb @@ -4,18 +4,6 @@ require Rails.root.join('db', 'post_migrate', '20171103140253_track_untracked_up describe TrackUntrackedUploads, :migration, :sidekiq do include TrackUntrackedUploadsHelpers - matcher :be_scheduled_migration do - match do |migration| - BackgroundMigrationWorker.jobs.any? do |job| - job['args'] == [migration] - end - end - - failure_message do |migration| - "Migration `#{migration}` with args `#{expected.inspect}` not scheduled!" - end - end - it 'correctly schedules the follow-up background migration' do Sidekiq::Testing.fake! do migrate! diff --git a/spec/support/background_migrations_matchers.rb b/spec/support/background_migrations_matchers.rb index 423c0e4cefc..f4127efc6ae 100644 --- a/spec/support/background_migrations_matchers.rb +++ b/spec/support/background_migrations_matchers.rb @@ -1,4 +1,4 @@ -RSpec::Matchers.define :be_scheduled_migration do |delay, *expected| +RSpec::Matchers.define :be_scheduled_delayed_migration do |delay, *expected| match do |migration| BackgroundMigrationWorker.jobs.any? do |job| job['args'] == [migration, expected] && @@ -11,3 +11,16 @@ RSpec::Matchers.define :be_scheduled_migration do |delay, *expected| 'not scheduled in expected time!' end end + +RSpec::Matchers.define :be_scheduled_migration do |*expected| + match do |migration| + BackgroundMigrationWorker.jobs.any? do |job| + args = job['args'].size == 1 ? [BackgroundMigrationWorker.jobs[0]['args'][0], []] : job['args'] + args == [migration, expected] + end + end + + failure_message do |migration| + "Migration `#{migration}` with args `#{expected.inspect}` not scheduled!" + end +end |