summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-06-29 12:26:37 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-06-29 12:26:37 +0200
commit42556419c99522e921299a3e247f115f580be7f1 (patch)
treea856bea6ddfd5969c90bcadeea23bb2e0cbffac8 /spec
parent8bd9cb6c87a1a1c51830360fe1aa1a228f9c768e (diff)
downloadgitlab-ce-42556419c99522e921299a3e247f115f580be7f1.tar.gz
Improve specs for background stage_id ref migration
Diffstat (limited to 'spec')
-rw-r--r--spec/migrations/migrate_stage_id_reference_in_background_spec.rb19
1 files changed, 13 insertions, 6 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 3eeca2e9659..046d9b351a8 100644
--- a/spec/migrations/migrate_stage_id_reference_in_background_spec.rb
+++ b/spec/migrations/migrate_stage_id_reference_in_background_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170628080858_migrate_stage_id_reference_in_background')
describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do
- matcher :have_scheduled_migration do |delay, *expected|
+ matcher :be_scheduled_migration do |delay, *expected|
match do |migration|
BackgroundMigrationWorker.jobs.any? do |job|
job['args'] == [migration, expected] &&
@@ -24,16 +24,22 @@ describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do
stub_const('MigrateStageIdReferenceInBackground::BATCH_SIZE', 2)
projects.create!(id: 123, name: 'gitlab1', path: 'gitlab1')
+ projects.create!(id: 345, name: 'gitlab2', path: 'gitlab2')
+
pipelines.create!(id: 1, project_id: 123, ref: 'master', sha: 'adf43c3a')
+ pipelines.create!(id: 2, project_id: 345, ref: 'feature', sha: 'cdf43c3c')
jobs.create!(id: 1, commit_id: 1, project_id: 123, stage_idx: 2, stage: 'build')
jobs.create!(id: 2, commit_id: 1, project_id: 123, stage_idx: 2, stage: 'build')
jobs.create!(id: 3, commit_id: 1, project_id: 123, stage_idx: 1, stage: 'test')
jobs.create!(id: 4, commit_id: 1, project_id: 123, stage_idx: 3, stage: 'deploy')
+ jobs.create!(id: 5, commit_id: 2, project_id: 345, stage_idx: 1, stage: 'test')
stages.create(id: 101, pipeline_id: 1, project_id: 123, name: 'test')
stages.create(id: 102, pipeline_id: 1, project_id: 123, name: 'build')
stages.create(id: 103, pipeline_id: 1, project_id: 123, name: 'deploy')
+
+ jobs.create!(id: 6, commit_id: 2, project_id: 345, stage_id: 101, stage_idx: 1, stage: 'test')
end
it 'correctly schedules background migrations' do
@@ -41,10 +47,11 @@ describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do
Timecop.freeze do
migrate!
- expect(described_class::MIGRATION).to have_scheduled_migration(5.minutes, 1)
- expect(described_class::MIGRATION).to have_scheduled_migration(5.minutes, 2)
- expect(described_class::MIGRATION).to have_scheduled_migration(10.minutes, 3)
- expect(described_class::MIGRATION).to have_scheduled_migration(10.minutes, 4)
+ expect(described_class::MIGRATION).to be_scheduled_migration(5.minutes, 1)
+ expect(described_class::MIGRATION).to be_scheduled_migration(5.minutes, 2)
+ expect(described_class::MIGRATION).to be_scheduled_migration(10.minutes, 3)
+ expect(described_class::MIGRATION).to be_scheduled_migration(10.minutes, 4)
+ expect(BackgroundMigrationWorker.jobs.size).to eq 5
end
end
end
@@ -55,7 +62,7 @@ describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do
migrate!
- expect(jobs.where(stage_id: nil)).to be_empty
+ expect(jobs.where(stage_id: nil)).to be_one
end
end
end