diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-05 10:54:48 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-05 10:54:48 +0200 |
commit | 6c477d5b9496829eb5cb56ef32a0dd813be7dc16 (patch) | |
tree | b744bfdbeed906271aac62917abf9d44f58d56c3 /spec | |
parent | c5ede858eab81e662c48761749ff2fa22dbfa9df (diff) | |
download | gitlab-ce-6c477d5b9496829eb5cb56ef32a0dd813be7dc16.tar.gz |
Move stages status migration to the background workerbackstage/gb/migrate-stages-statuses
Diffstat (limited to 'spec')
-rw-r--r-- | spec/migrations/migrate_stage_id_reference_in_background_spec.rb | 13 | ||||
-rw-r--r-- | spec/migrations/migrate_stages_statuses_spec.rb | 28 | ||||
-rw-r--r-- | spec/support/background_migrations_matchers.rb | 13 |
3 files changed, 36 insertions, 18 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 a32a7fceb68..ff137cc7d47 100644 --- a/spec/migrations/migrate_stage_id_reference_in_background_spec.rb +++ b/spec/migrations/migrate_stage_id_reference_in_background_spec.rb @@ -2,19 +2,6 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20170628080858_migrate_stage_id_reference_in_background') describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do - matcher :be_scheduled_migration do |delay, *expected| - match do |migration| - BackgroundMigrationWorker.jobs.any? do |job| - job['args'] == [migration, expected] && - job['at'].to_i == (delay.to_i + Time.now.to_i) - end - end - - failure_message do |migration| - "Migration `#{migration}` with args `#{expected.inspect}` not scheduled!" - end - end - let(:jobs) { table(:ci_builds) } let(:stages) { table(:ci_stages) } let(:pipelines) { table(:ci_pipelines) } diff --git a/spec/migrations/migrate_stages_statuses_spec.rb b/spec/migrations/migrate_stages_statuses_spec.rb index 478ddad262a..8463583cef3 100644 --- a/spec/migrations/migrate_stages_statuses_spec.rb +++ b/spec/migrations/migrate_stages_statuses_spec.rb @@ -11,6 +11,8 @@ describe MigrateStagesStatuses, :migration do failed: 4, canceled: 5, skipped: 6, manual: 7 } before do + stub_const("#{described_class.name}::BATCH_SIZE", 2) + projects.create!(id: 1, name: 'gitlab1', path: 'gitlab1') projects.create!(id: 2, name: 'gitlab2', path: 'gitlab2') @@ -31,15 +33,31 @@ describe MigrateStagesStatuses, :migration do end it 'correctly migrates stages statuses' do - expect(stages.where(status: nil).count).to eq 3 + Sidekiq::Testing.inline! do + expect(stages.where(status: nil).count).to eq 3 - migrate! + migrate! - expect(stages.where(status: nil)).to be_empty - expect(stages.all.order('id ASC').pluck(:status)) - .to eq [STATUSES[:running], STATUSES[:failed], STATUSES[:success]] + expect(stages.where(status: nil)).to be_empty + expect(stages.all.order('id ASC').pluck(:status)) + .to eq [STATUSES[:running], STATUSES[:failed], STATUSES[:success]] + end end + it 'correctly schedules background migrations' do + Sidekiq::Testing.fake! do + Timecop.freeze do + migrate! + + 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(BackgroundMigrationWorker.jobs.size).to eq 3 + end + end + end + + def create_job(project:, pipeline:, stage:, status:, **opts) stages = { test: 1, build: 2, deploy: 3} diff --git a/spec/support/background_migrations_matchers.rb b/spec/support/background_migrations_matchers.rb new file mode 100644 index 00000000000..423c0e4cefc --- /dev/null +++ b/spec/support/background_migrations_matchers.rb @@ -0,0 +1,13 @@ +RSpec::Matchers.define :be_scheduled_migration do |delay, *expected| + match do |migration| + BackgroundMigrationWorker.jobs.any? do |job| + job['args'] == [migration, expected] && + job['at'].to_i == (delay.to_i + Time.now.to_i) + end + end + + failure_message do |migration| + "Migration `#{migration}` with args `#{expected.inspect}` " \ + 'not scheduled in expected time!' + end +end |