Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/background_migration/batching_strategies')
-rw-r--r--spec/lib/gitlab/background_migration/batching_strategies/backfill_issue_work_item_type_batching_strategy_spec.rb135
-rw-r--r--spec/lib/gitlab/background_migration/batching_strategies/backfill_project_statistics_with_container_registry_size_batching_strategy_spec.rb133
-rw-r--r--spec/lib/gitlab/background_migration/batching_strategies/dismissed_vulnerabilities_strategy_spec.rb112
-rw-r--r--spec/lib/gitlab/background_migration/batching_strategies/primary_key_batching_strategy_spec.rb23
-rw-r--r--spec/lib/gitlab/background_migration/batching_strategies/remove_backfilled_job_artifacts_expire_at_batching_strategy_spec.rb7
5 files changed, 17 insertions, 393 deletions
diff --git a/spec/lib/gitlab/background_migration/batching_strategies/backfill_issue_work_item_type_batching_strategy_spec.rb b/spec/lib/gitlab/background_migration/batching_strategies/backfill_issue_work_item_type_batching_strategy_spec.rb
deleted file mode 100644
index 3cba99bfe51..00000000000
--- a/spec/lib/gitlab/background_migration/batching_strategies/backfill_issue_work_item_type_batching_strategy_spec.rb
+++ /dev/null
@@ -1,135 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::BackgroundMigration::BatchingStrategies::BackfillIssueWorkItemTypeBatchingStrategy, '#next_batch', schema: 20220326161803 do # rubocop:disable Layout/LineLength
- # let! can't be used in migration specs because all tables but `work_item_types` are deleted after each spec
- let!(:issue_type_enum) { { issue: 0, incident: 1, test_case: 2, requirement: 3, task: 4 } }
- let!(:namespace) { table(:namespaces).create!(name: 'namespace', path: 'namespace') }
- let!(:project) { table(:projects).create!(namespace_id: namespace.id) }
- let!(:issues_table) { table(:issues) }
- let!(:task_type) { table(:work_item_types).find_by!(namespace_id: nil, base_type: issue_type_enum[:task]) }
-
- let!(:issue1) { issues_table.create!(project_id: project.id, issue_type: issue_type_enum[:issue]) }
- let!(:task1) { issues_table.create!(project_id: project.id, issue_type: issue_type_enum[:task]) }
- let!(:issue2) { issues_table.create!(project_id: project.id, issue_type: issue_type_enum[:issue]) }
- let!(:issue3) { issues_table.create!(project_id: project.id, issue_type: issue_type_enum[:issue]) }
- let!(:task2) { issues_table.create!(project_id: project.id, issue_type: issue_type_enum[:task]) }
- let!(:incident1) { issues_table.create!(project_id: project.id, issue_type: issue_type_enum[:incident]) }
- # test_case is EE only, but enum values exist on the FOSS model
- let!(:test_case1) { issues_table.create!(project_id: project.id, issue_type: issue_type_enum[:test_case]) }
-
- let!(:task3) do
- issues_table.create!(project_id: project.id, issue_type: issue_type_enum[:task], work_item_type_id: task_type.id)
- end
-
- let!(:task4) { issues_table.create!(project_id: project.id, issue_type: issue_type_enum[:task]) }
-
- let!(:batching_strategy) { described_class.new(connection: ActiveRecord::Base.connection) }
-
- context 'when issue_type is issue' do
- let(:job_arguments) { [issue_type_enum[:issue], 'irrelevant_work_item_id'] }
-
- context 'when starting on the first batch' do
- it 'returns the bounds of the next batch' do
- batch_bounds = next_batch(issue1.id, 2)
-
- expect(batch_bounds).to match_array([issue1.id, issue2.id])
- end
- end
-
- context 'when additional batches remain' do
- it 'returns the bounds of the next batch' do
- batch_bounds = next_batch(issue2.id, 2)
-
- expect(batch_bounds).to match_array([issue2.id, issue3.id])
- end
- end
-
- context 'when on the final batch' do
- it 'returns the bounds of the next batch' do
- batch_bounds = next_batch(issue3.id, 2)
-
- expect(batch_bounds).to match_array([issue3.id, issue3.id])
- end
- end
-
- context 'when no additional batches remain' do
- it 'returns nil' do
- batch_bounds = next_batch(issue3.id + 1, 1)
-
- expect(batch_bounds).to be_nil
- end
- end
- end
-
- context 'when issue_type is incident' do
- let(:job_arguments) { [issue_type_enum[:incident], 'irrelevant_work_item_id'] }
-
- context 'when starting on the first batch' do
- it 'returns the bounds of the next batch with only one element' do
- batch_bounds = next_batch(incident1.id, 2)
-
- expect(batch_bounds).to match_array([incident1.id, incident1.id])
- end
- end
- end
-
- context 'when issue_type is requirement and there are no matching records' do
- let(:job_arguments) { [issue_type_enum[:requirement], 'irrelevant_work_item_id'] }
-
- context 'when starting on the first batch' do
- it 'returns nil' do
- batch_bounds = next_batch(1, 2)
-
- expect(batch_bounds).to be_nil
- end
- end
- end
-
- context 'when issue_type is task' do
- let(:job_arguments) { [issue_type_enum[:task], 'irrelevant_work_item_id'] }
-
- context 'when starting on the first batch' do
- it 'returns the bounds of the next batch' do
- batch_bounds = next_batch(task1.id, 2)
-
- expect(batch_bounds).to match_array([task1.id, task2.id])
- end
- end
-
- context 'when additional batches remain' do
- it 'returns the bounds of the next batch, does not skip records where FK is already set' do
- batch_bounds = next_batch(task2.id, 2)
-
- expect(batch_bounds).to match_array([task2.id, task3.id])
- end
- end
-
- context 'when on the final batch' do
- it 'returns the bounds of the next batch' do
- batch_bounds = next_batch(task4.id, 2)
-
- expect(batch_bounds).to match_array([task4.id, task4.id])
- end
- end
-
- context 'when no additional batches remain' do
- it 'returns nil' do
- batch_bounds = next_batch(task4.id + 1, 1)
-
- expect(batch_bounds).to be_nil
- end
- end
- end
-
- def next_batch(min_value, batch_size)
- batching_strategy.next_batch(
- :issues,
- :id,
- batch_min_value: min_value,
- batch_size: batch_size,
- job_arguments: job_arguments
- )
- end
-end
diff --git a/spec/lib/gitlab/background_migration/batching_strategies/backfill_project_statistics_with_container_registry_size_batching_strategy_spec.rb b/spec/lib/gitlab/background_migration/batching_strategies/backfill_project_statistics_with_container_registry_size_batching_strategy_spec.rb
index 94e9bcf9207..7076e82ea34 100644
--- a/spec/lib/gitlab/background_migration/batching_strategies/backfill_project_statistics_with_container_registry_size_batching_strategy_spec.rb
+++ b/spec/lib/gitlab/background_migration/batching_strategies/backfill_project_statistics_with_container_registry_size_batching_strategy_spec.rb
@@ -2,137 +2,6 @@
require 'spec_helper'
-RSpec.describe Gitlab::BackgroundMigration::BatchingStrategies::BackfillProjectStatisticsWithContainerRegistrySizeBatchingStrategy, '#next_batch' do # rubocop:disable Layout/LineLength
- let(:batching_strategy) { described_class.new(connection: ActiveRecord::Base.connection) }
- let(:namespace) { table(:namespaces) }
- let(:project) { table(:projects) }
- let(:container_repositories) { table(:container_repositories) }
-
- let!(:group) do
- namespace.create!(
- name: 'namespace1', type: 'Group', path: 'space1'
- )
- end
-
- let!(:proj_namespace1) do
- namespace.create!(
- name: 'proj1', path: 'proj1', type: 'Project', parent_id: group.id
- )
- end
-
- let!(:proj_namespace2) do
- namespace.create!(
- name: 'proj2', path: 'proj2', type: 'Project', parent_id: group.id
- )
- end
-
- let!(:proj_namespace3) do
- namespace.create!(
- name: 'proj3', path: 'proj3', type: 'Project', parent_id: group.id
- )
- end
-
- let!(:proj1) do
- project.create!(
- name: 'proj1', path: 'proj1', namespace_id: group.id, project_namespace_id: proj_namespace1.id
- )
- end
-
- let!(:proj2) do
- project.create!(
- name: 'proj2', path: 'proj2', namespace_id: group.id, project_namespace_id: proj_namespace2.id
- )
- end
-
- let!(:proj3) do
- project.create!(
- name: 'proj3', path: 'proj3', namespace_id: group.id, project_namespace_id: proj_namespace3.id
- )
- end
-
- let!(:con1) do
- container_repositories.create!(
- project_id: proj1.id,
- name: "ContReg_#{proj1.id}:1",
- migration_state: 'import_done',
- created_at: Date.new(2022, 01, 20)
- )
- end
-
- let!(:con2) do
- container_repositories.create!(
- project_id: proj1.id,
- name: "ContReg_#{proj1.id}:2",
- migration_state: 'import_done',
- created_at: Date.new(2022, 01, 20)
- )
- end
-
- let!(:con3) do
- container_repositories.create!(
- project_id: proj2.id,
- name: "ContReg_#{proj2.id}:1",
- migration_state: 'import_done',
- created_at: Date.new(2022, 01, 20)
- )
- end
-
- let!(:con4) do
- container_repositories.create!(
- project_id: proj3.id,
- name: "ContReg_#{proj3.id}:1",
- migration_state: 'default',
- created_at: Date.new(2022, 02, 20)
- )
- end
-
- let!(:con5) do
- container_repositories.create!(
- project_id: proj3.id,
- name: "ContReg_#{proj3.id}:2",
- migration_state: 'default',
- created_at: Date.new(2022, 02, 20)
- )
- end
-
+RSpec.describe Gitlab::BackgroundMigration::BatchingStrategies::BackfillProjectStatisticsWithContainerRegistrySizeBatchingStrategy do # rubocop:disable Layout/LineLength
it { expect(described_class).to be < Gitlab::BackgroundMigration::BatchingStrategies::PrimaryKeyBatchingStrategy }
-
- context 'when starting on the first batch' do
- it 'returns the bounds of the next batch' do
- batch_bounds = batching_strategy.next_batch(
- :container_repositories,
- :project_id,
- batch_min_value: con1.project_id,
- batch_size: 3,
- job_arguments: []
- )
- expect(batch_bounds).to eq([con1.project_id, con4.project_id])
- end
- end
-
- context 'when additional batches remain' do
- it 'returns the bounds of the next batch' do
- batch_bounds = batching_strategy.next_batch(
- :container_repositories,
- :project_id,
- batch_min_value: con3.project_id,
- batch_size: 3,
- job_arguments: []
- )
-
- expect(batch_bounds).to eq([con3.project_id, con5.project_id])
- end
- end
-
- context 'when no additional batches remain' do
- it 'returns nil' do
- batch_bounds = batching_strategy.next_batch(:container_repositories,
- :project_id,
- batch_min_value: con5.project_id + 1,
- batch_size: 1, job_arguments: []
- )
-
- expect(batch_bounds).to be_nil
- end
- end
end
diff --git a/spec/lib/gitlab/background_migration/batching_strategies/dismissed_vulnerabilities_strategy_spec.rb b/spec/lib/gitlab/background_migration/batching_strategies/dismissed_vulnerabilities_strategy_spec.rb
index f96c7de50f2..e4bef81e0bd 100644
--- a/spec/lib/gitlab/background_migration/batching_strategies/dismissed_vulnerabilities_strategy_spec.rb
+++ b/spec/lib/gitlab/background_migration/batching_strategies/dismissed_vulnerabilities_strategy_spec.rb
@@ -3,117 +3,5 @@
require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::BatchingStrategies::DismissedVulnerabilitiesStrategy, '#next_batch' do
- let(:batching_strategy) { described_class.new(connection: ActiveRecord::Base.connection) }
- let(:namespace) { table(:namespaces).create!(name: 'user', path: 'user') }
- let(:users) { table(:users) }
- let(:user) { create_user! }
- let(:project) do
- table(:projects).create!(
- namespace_id: namespace.id,
- project_namespace_id: namespace.id,
- packages_enabled: false)
- end
-
- let(:vulnerabilities) { table(:vulnerabilities) }
-
- let!(:vulnerability1) do
- create_vulnerability!(
- project_id: project.id,
- author_id: user.id,
- dismissed_at: Time.current
- )
- end
-
- let!(:vulnerability2) do
- create_vulnerability!(
- project_id: project.id,
- author_id: user.id,
- dismissed_at: Time.current
- )
- end
-
- let!(:vulnerability3) do
- create_vulnerability!(
- project_id: project.id,
- author_id: user.id,
- dismissed_at: Time.current
- )
- end
-
- let!(:vulnerability4) do
- create_vulnerability!(
- project_id: project.id,
- author_id: user.id,
- dismissed_at: nil
- )
- end
-
it { expect(described_class).to be < Gitlab::BackgroundMigration::BatchingStrategies::PrimaryKeyBatchingStrategy }
-
- context 'when starting on the first batch' do
- it 'returns the bounds of the next batch' do
- batch_bounds = batching_strategy.next_batch(
- :vulnerabilities,
- :id,
- batch_min_value: vulnerability1.id,
- batch_size: 2,
- job_arguments: []
- )
- expect(batch_bounds).to eq([vulnerability1.id, vulnerability2.id])
- end
- end
-
- context 'when additional batches remain' do
- it 'returns the bounds of the next batch and skips the records that do not have `dismissed_at` set' do
- batch_bounds = batching_strategy.next_batch(
- :vulnerabilities,
- :id,
- batch_min_value: vulnerability3.id,
- batch_size: 2,
- job_arguments: []
- )
-
- expect(batch_bounds).to eq([vulnerability3.id, vulnerability3.id])
- end
- end
-
- context 'when no additional batches remain' do
- it 'returns nil' do
- batch_bounds = batching_strategy.next_batch(
- :vulnerabilities,
- :id,
- batch_min_value: vulnerability4.id + 1,
- batch_size: 1,
- job_arguments: []
- )
-
- expect(batch_bounds).to be_nil
- end
- end
-
- private
-
- def create_vulnerability!(
- project_id:, author_id:, title: 'test', severity: 7, confidence: 7, report_type: 0, state: 1, dismissed_at: nil
- )
- vulnerabilities.create!(
- project_id: project_id,
- author_id: author_id,
- title: title,
- severity: severity,
- confidence: confidence,
- report_type: report_type,
- state: state,
- dismissed_at: dismissed_at
- )
- end
-
- def create_user!(name: "Example User", email: "user@example.com", user_type: nil)
- users.create!(
- name: name,
- email: email,
- username: name,
- projects_limit: 10
- )
- end
end
diff --git a/spec/lib/gitlab/background_migration/batching_strategies/primary_key_batching_strategy_spec.rb b/spec/lib/gitlab/background_migration/batching_strategies/primary_key_batching_strategy_spec.rb
index 9fdd7bf8adc..37fdd209622 100644
--- a/spec/lib/gitlab/background_migration/batching_strategies/primary_key_batching_strategy_spec.rb
+++ b/spec/lib/gitlab/background_migration/batching_strategies/primary_key_batching_strategy_spec.rb
@@ -60,26 +60,21 @@ RSpec.describe Gitlab::BackgroundMigration::BatchingStrategies::PrimaryKeyBatchi
expect(batch_bounds).to eq([namespace4.id, namespace4.id])
end
- end
-
- context 'additional filters' do
- let(:strategy_with_filters) do
- Class.new(described_class) do
- def apply_additional_filters(relation, job_arguments:, job_class: nil)
- min_id = job_arguments.first
- relation.where.not(type: 'Project').where('id >= ?', min_id)
+ context 'when scope has a join which makes the column name ambiguous' do
+ let(:job_class) do
+ Class.new(Gitlab::BackgroundMigration::BatchedMigrationJob) do
+ scope_to ->(r) { r.joins('LEFT JOIN users ON users.id = namespaces.owner_id') }
end
end
- end
- let(:batching_strategy) { strategy_with_filters.new(connection: ActiveRecord::Base.connection) }
- let!(:namespace5) { namespaces.create!(name: 'batchtest5', path: 'batch-test5', type: 'Project') }
+ it 'executes the correct query' do
+ expect(job_class).to receive(:generic_instance).and_call_original
- it 'applies additional filters' do
- batch_bounds = batching_strategy.next_batch(:namespaces, :id, batch_min_value: namespace4.id, batch_size: 3, job_arguments: [1])
+ batch_bounds = batching_strategy.next_batch(:namespaces, :id, batch_min_value: namespace4.id, batch_size: 3, job_arguments: [], job_class: job_class)
- expect(batch_bounds).to eq([namespace4.id, namespace4.id])
+ expect(batch_bounds).to eq([namespace4.id, namespace4.id])
+ end
end
end
end
diff --git a/spec/lib/gitlab/background_migration/batching_strategies/remove_backfilled_job_artifacts_expire_at_batching_strategy_spec.rb b/spec/lib/gitlab/background_migration/batching_strategies/remove_backfilled_job_artifacts_expire_at_batching_strategy_spec.rb
new file mode 100644
index 00000000000..e296a46ea2f
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/batching_strategies/remove_backfilled_job_artifacts_expire_at_batching_strategy_spec.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::BackgroundMigration::BatchingStrategies::RemoveBackfilledJobArtifactsExpireAtBatchingStrategy do # rubocop:disable Layout/LineLength
+ it { expect(described_class).to be < Gitlab::BackgroundMigration::BatchingStrategies::PrimaryKeyBatchingStrategy }
+end