summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-12-05 12:02:07 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-01-06 14:09:59 +0100
commit2ab69f0d0c825f8546f189a61189246d6c90b7ff (patch)
treee043bfc888e2bfe1e5ae2eb46a86af48d5c0171c /spec
parent6d972724d426938a0bfd6744dc6464ec5f7e17f9 (diff)
downloadgitlab-ce-2ab69f0d0c825f8546f189a61189246d6c90b7ff.tar.gz
Schedule full build stage migration in the background
For builds that are still missing `stage_id`.
Diffstat (limited to 'spec')
-rw-r--r--spec/migrations/schedule_build_stage_migration_spec.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/migrations/schedule_build_stage_migration_spec.rb b/spec/migrations/schedule_build_stage_migration_spec.rb
new file mode 100644
index 00000000000..f80c0a94b32
--- /dev/null
+++ b/spec/migrations/schedule_build_stage_migration_spec.rb
@@ -0,0 +1,43 @@
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20171205101928_schedule_build_stage_migration')
+
+describe ScheduleBuildStageMigration, :migration do
+ let(:projects) { table(:projects) }
+ let(:pipelines) { table(:ci_pipelines) }
+ let(:stages) { table(:ci_stages) }
+ let(:jobs) { table(:ci_builds) }
+
+ before do
+ ##
+ # Dependencies
+ #
+ projects.create!(id: 123, name: 'gitlab', path: 'gitlab-ce')
+ pipelines.create!(id: 1, project_id: 123, ref: 'master', sha: 'adf43c3a')
+ stages.create!(id: 1, project_id: 123, pipeline_id: 1, name: 'test')
+
+ ##
+ # CI/CD jobs
+ #
+ jobs.create!(id: 10, commit_id: 1, project_id: 123, stage_id: nil)
+ jobs.create!(id: 20, commit_id: 1, project_id: 123, stage_id: nil)
+ jobs.create!(id: 30, commit_id: 1, project_id: 123, stage_id: nil)
+ jobs.create!(id: 40, commit_id: 1, project_id: 123, stage_id: 1)
+ end
+
+ before do
+ stub_const("#{described_class}::BATCH", 1)
+ end
+
+ it 'schedules background migrations in batches in bulk' do
+ Sidekiq::Testing.fake! do
+ Timecop.freeze do
+ migrate!
+
+ expect(described_class::MIGRATION).to be_scheduled_migration(1.minutes, 10)
+ expect(described_class::MIGRATION).to be_scheduled_migration(2.minutes, 20)
+ expect(described_class::MIGRATION).to be_scheduled_migration(3.minutes, 30)
+ expect(BackgroundMigrationWorker.jobs.size).to eq 3
+ end
+ end
+ end
+end