diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-01 16:38:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-01 16:38:24 +0300 |
commit | 0396082c12f518f48e136968dbf0b4e5f774641c (patch) | |
tree | 9ee22b3f2d65483c316d30397b7e065d4dec5fec /spec | |
parent | cb7e80d1211dae947e40290a834cbe29ee36364e (diff) |
Add latest changes from gitlab-org/gitlab@15-2-stable-ee
Diffstat (limited to 'spec')
-rw-r--r-- | spec/migrations/reschedule_backfill_imported_issue_search_data_spec.rb | 85 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 10 | ||||
-rw-r--r-- | spec/requests/api/ci/runner/jobs_artifacts_spec.rb | 6 |
3 files changed, 76 insertions, 25 deletions
diff --git a/spec/migrations/reschedule_backfill_imported_issue_search_data_spec.rb b/spec/migrations/reschedule_backfill_imported_issue_search_data_spec.rb index 7d1377bbeba..7581c201a59 100644 --- a/spec/migrations/reschedule_backfill_imported_issue_search_data_spec.rb +++ b/spec/migrations/reschedule_backfill_imported_issue_search_data_spec.rb @@ -6,8 +6,22 @@ require_migration! RSpec.describe RescheduleBackfillImportedIssueSearchData do let_it_be(:reschedule_migration) { described_class::MIGRATION } - context 'when BackfillIssueSearchData.max_value is nil' do - it 'schedules a new batched migration with a default value' do + def create_batched_migration(max_value:) + Gitlab::Database::BackgroundMigration::BatchedMigration + .create!( + max_value: max_value, + batch_size: 200, + sub_batch_size: 20, + interval: 120, + job_class_name: 'BackfillIssueSearchData', + table_name: 'issues', + column_name: 'id', + gitlab_schema: 'glschema' + ) + end + + shared_examples 'backfill rescheduler' do + it 'schedules a new batched migration' do reversible_migration do |migration| migration.before -> { expect(reschedule_migration).not_to have_scheduled_batched_migration @@ -17,39 +31,60 @@ RSpec.describe RescheduleBackfillImportedIssueSearchData do table_name: :issues, column_name: :id, interval: described_class::DELAY_INTERVAL, - batch_min_value: described_class::BATCH_MIN_VALUE + batch_min_value: batch_min_value ) } end end end + context 'when BackfillIssueSearchData.max_value is nil' do + let(:batch_min_value) { described_class::BATCH_MIN_VALUE } + + it_behaves_like 'backfill rescheduler' + end + context 'when BackfillIssueSearchData.max_value exists' do + let(:batch_min_value) { described_class::BATCH_MIN_VALUE } + before do - Gitlab::Database::BackgroundMigration::BatchedMigration - .create!( - max_value: 200, - batch_size: 200, - sub_batch_size: 20, - interval: 120, - job_class_name: 'BackfillIssueSearchData', - table_name: 'issues', - column_name: 'id', - gitlab_schema: 'glschema' - ) + create_batched_migration(max_value: 200) end - it 'schedules a new batched migration with a custom max_value' do - reversible_migration do |migration| - migration.after -> { - expect(reschedule_migration).to have_scheduled_batched_migration( - table_name: :issues, - column_name: :id, - interval: described_class::DELAY_INTERVAL, - batch_min_value: 200 - ) - } - end + it_behaves_like 'backfill rescheduler' + end + + context 'when an issue is available' do + let_it_be(:namespaces_table) { table(:namespaces) } + let_it_be(:projects_table) { table(:projects) } + + let(:namespace) { namespaces_table.create!(name: 'gitlab-org', path: 'gitlab-org') } + let(:project) { projects_table.create!(name: 'gitlab', path: 'gitlab-org/gitlab-ce', namespace_id: namespace.id, project_namespace_id: namespace.id) } # rubocop:disable Layout/LineLength + let(:issue) { table(:issues).create!(project_id: project.id, title: 'test title', description: 'test description') } + + before do + create_batched_migration(max_value: max_value) + end + + context 'when BackfillIssueSearchData.max_value = Issue.maximum(:id)' do + let(:max_value) { issue.id } + let(:batch_min_value) { max_value } + + it_behaves_like 'backfill rescheduler' + end + + context 'when BackfillIssueSearchData.max_value > Issue.maximum(:id)' do + let(:max_value) { issue.id + 1 } + let(:batch_min_value) { issue.id } + + it_behaves_like 'backfill rescheduler' + end + + context 'when BackfillIssueSearchData.max_value < Issue.maximum(:id)' do + let(:max_value) { issue.id - 1 } + let(:batch_min_value) { max_value } + + it_behaves_like 'backfill rescheduler' end end end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 081fa6cbbae..6a71b2cfbed 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -5039,6 +5039,16 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do expect(pipeline.age_in_minutes).to eq 120 end end + + context 'when pipeline has no created_at' do + before do + pipeline.update!(created_at: nil) + end + + it 'returns zero' do + expect(pipeline.age_in_minutes).to eq 0 + end + end end context 'when pipeline has been loaded without all attributes' do diff --git a/spec/requests/api/ci/runner/jobs_artifacts_spec.rb b/spec/requests/api/ci/runner/jobs_artifacts_spec.rb index 5767fa4326e..cd8c3dd2806 100644 --- a/spec/requests/api/ci/runner/jobs_artifacts_spec.rb +++ b/spec/requests/api/ci/runner/jobs_artifacts_spec.rb @@ -844,7 +844,13 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do 'Content-Disposition' => %q(attachment; filename="ci_build_artifacts.zip"; filename*=UTF-8''ci_build_artifacts.zip) } end + before do + allow(Gitlab::ApplicationContext).to receive(:push).and_call_original + end + it 'downloads artifacts' do + expect(Gitlab::ApplicationContext).to receive(:push).with(artifact: an_instance_of(Ci::JobArtifact)).once.and_call_original + download_artifact expect(response).to have_gitlab_http_status(:ok) |