Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/migrations/drop_background_migration_jobs_spec.rb')
-rw-r--r--spec/migrations/drop_background_migration_jobs_spec.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/migrations/drop_background_migration_jobs_spec.rb b/spec/migrations/drop_background_migration_jobs_spec.rb
new file mode 100644
index 00000000000..ac76e897f6c
--- /dev/null
+++ b/spec/migrations/drop_background_migration_jobs_spec.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'migrate', '20200116051619_drop_background_migration_jobs.rb')
+
+describe DropBackgroundMigrationJobs, :sidekiq, :redis, :migration, schema: 2020_01_16_051619 do
+ subject(:migration) { described_class.new }
+
+ describe '#up' do
+ context 'there are only affected jobs on the queue' do
+ it 'removes enqueued ActivatePrometheusServicesForSharedClusterApplications background jobs' do
+ Sidekiq::Testing.disable! do # https://github.com/mperham/sidekiq/wiki/testing#api Sidekiq's API does not have a testing mode
+ Sidekiq::Client.push('queue' => described_class::QUEUE, 'class' => ::BackgroundMigrationWorker, 'args' => [described_class::DROPPED_JOB_CLASS, 1])
+
+ expect { migration.up }.to change { Sidekiq::Queue.new(described_class::QUEUE).size }.from(1).to(0)
+ end
+ end
+ end
+
+ context "there aren't any affected jobs on the queue" do
+ it 'skips other enqueued jobs' do
+ Sidekiq::Testing.disable! do
+ Sidekiq::Client.push('queue' => described_class::QUEUE, 'class' => ::BackgroundMigrationWorker, 'args' => ['SomeOtherClass', 1])
+
+ expect { migration.up }.not_to change { Sidekiq::Queue.new(described_class::QUEUE).size }
+ end
+ end
+ end
+
+ context "there are multiple types of jobs on the queue" do
+ it 'skips other enqueued jobs' do
+ Sidekiq::Testing.disable! do
+ queue = Sidekiq::Queue.new(described_class::QUEUE)
+ # this job will be deleted
+ Sidekiq::Client.push('queue' => described_class::QUEUE, 'class' => ::BackgroundMigrationWorker, 'args' => [described_class::DROPPED_JOB_CLASS, 1])
+ # this jobs will be skipped
+ skipped_jobs_args = [['SomeOtherClass', 1], [described_class::DROPPED_JOB_CLASS, 'wrong id type'], [described_class::DROPPED_JOB_CLASS, 1, 'some wired argument']]
+ skipped_jobs_args.each do |args|
+ Sidekiq::Client.push('queue' => described_class::QUEUE, 'class' => ::BackgroundMigrationWorker, 'args' => args)
+ end
+
+ migration.up
+
+ expect(queue.size).to be 3
+ expect(queue.map(&:args)).to match_array skipped_jobs_args
+ end
+ end
+ end
+
+ context "other queues" do
+ it 'does not modify them' do
+ Sidekiq::Testing.disable! do
+ Sidekiq::Client.push('queue' => 'other', 'class' => ::BackgroundMigrationWorker, 'args' => ['SomeOtherClass', 1])
+ Sidekiq::Client.push('queue' => 'other', 'class' => ::BackgroundMigrationWorker, 'args' => [described_class::DROPPED_JOB_CLASS, 1])
+
+ expect { migration.up }.not_to change { Sidekiq::Queue.new('other').size }
+ end
+ end
+ end
+ end
+end