diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /spec/migrations/schedule_delete_orphaned_deployments_spec.rb | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/migrations/schedule_delete_orphaned_deployments_spec.rb')
-rw-r--r-- | spec/migrations/schedule_delete_orphaned_deployments_spec.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/migrations/schedule_delete_orphaned_deployments_spec.rb b/spec/migrations/schedule_delete_orphaned_deployments_spec.rb new file mode 100644 index 00000000000..618958a3d90 --- /dev/null +++ b/spec/migrations/schedule_delete_orphaned_deployments_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require_migration! + +RSpec.describe ScheduleDeleteOrphanedDeployments, :sidekiq, schema: 20210617161348 do + let!(:namespace) { table(:namespaces).create!(name: 'user', path: 'user') } + let!(:project) { table(:projects).create!(namespace_id: namespace.id) } + let!(:environment) { table(:environments).create!(name: 'production', slug: 'production', project_id: project.id) } + let(:background_migration_jobs) { table(:background_migration_jobs) } + + before do + create_deployment!(environment.id, project.id) + create_deployment!(environment.id, project.id) + create_deployment!(environment.id, project.id) + create_deployment!(non_existing_record_id, project.id) + create_deployment!(non_existing_record_id, project.id) + create_deployment!(non_existing_record_id, project.id) + create_deployment!(non_existing_record_id, project.id) + + stub_const("#{described_class}::BATCH_SIZE", 1) + end + + it 'schedules DeleteOrphanedDeployments background jobs' do + Sidekiq::Testing.fake! do + freeze_time do + migrate! + + expect(BackgroundMigrationWorker.jobs.size).to eq(7) + table(:deployments).find_each do |deployment| + expect(described_class::MIGRATION).to be_scheduled_migration(deployment.id, deployment.id) + end + end + end + end + + def create_deployment!(environment_id, project_id) + table(:deployments).create!( + environment_id: environment_id, + project_id: project_id, + ref: 'master', + tag: false, + sha: 'x', + status: 1, + iid: table(:deployments).count + 1) + end +end |