summaryrefslogtreecommitdiff
path: root/spec/migrations
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-06-28 15:24:53 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-07 15:08:15 +0200
commit07693b43745e31e47466a9f1f5b73de894323a5d (patch)
tree07198303a879a4aa6cc077b8cf9cff2f79949856 /spec/migrations
parent1dc20f7ac7dbb68464cb4ea2727fd4e7171cfba8 (diff)
downloadgitlab-ce-07693b43745e31e47466a9f1f5b73de894323a5d.tar.gz
Add specs for delayed stage_id background migrations
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/migrate_stage_id_reference_in_background_spec.rb51
1 files changed, 47 insertions, 4 deletions
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 d515eb42b9d..8b497656377 100644
--- a/spec/migrations/migrate_stage_id_reference_in_background_spec.rb
+++ b/spec/migrations/migrate_stage_id_reference_in_background_spec.rb
@@ -1,7 +1,37 @@
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170628080858_migrate_stage_id_reference_in_background')
-describe MigrateStageIdReferenceInBackground, :migration, :redis do
+RSpec::Matchers.define :have_migrated do |*expected|
+ match do |migration|
+ BackgroundMigrationWorker.jobs.any? do |job|
+ job['enqueued_at'].present? && job['args'] == [migration, expected]
+ end
+ end
+
+ failure_message do |migration|
+ <<-EOS
+ Background migration `#{migration}` with args `#{expected.inspect}`
+ not migrated!
+ EOS
+ end
+end
+
+RSpec::Matchers.define :have_scheduled_migration do |time, *expected|
+ match do |migration|
+ BackgroundMigrationWorker.jobs.any? do |job|
+ job['args'] == [migration, expected] && job['at'] >= time
+ end
+ end
+
+ failure_message do |migration|
+ <<-EOS
+ Background migration `#{migration}` with args `#{expected.inspect}`
+ not scheduled!
+ EOS
+ end
+end
+
+describe MigrateStageIdReferenceInBackground, :migration do
let(:jobs) { table(:ci_builds) }
let(:stages) { table(:ci_stages) }
let(:pipelines) { table(:ci_pipelines) }
@@ -23,11 +53,24 @@ describe MigrateStageIdReferenceInBackground, :migration, :redis do
stages.create(id: 103, pipeline_id: 1, project_id: 123, name: 'deploy')
end
+ it 'correctly schedules background migrations' do
+ Sidekiq::Testing.fake! do
+ migrate!
+
+ expect(described_class::MIGRATION).to have_migrated(1)
+ expect(described_class::MIGRATION).to have_migrated(2)
+ expect(described_class::MIGRATION).to have_scheduled_migration(5.minutes, 3)
+ expect(described_class::MIGRATION).to have_scheduled_migration(5.minutes, 4)
+ end
+ end
+
it 'schedules background migrations' do
- expect(jobs.where(stage_id: nil)).to be_present
+ Sidekiq::Testing.inline! do
+ expect(jobs.where(stage_id: nil)).to be_present
- migrate!
+ migrate!
- expect(jobs.where(stage_id: nil)).to be_empty
+ expect(jobs.where(stage_id: nil)).to be_empty
+ end
end
end