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:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-09-06 09:09:17 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-09-06 09:09:17 +0300
commit578fc865330cb9ce65746ea5c03e993348e62c96 (patch)
tree3c8175f1d2192633a17a4a85b0824b07d055c990 /spec/migrations
parent23d951df2d16aea96dbd78fd8afe2e22a4794115 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/remove_duplicate_dast_site_tokens_with_same_token_spec.rb53
-rw-r--r--spec/migrations/slice_merge_request_diff_commit_migrations_spec.rb69
2 files changed, 122 insertions, 0 deletions
diff --git a/spec/migrations/remove_duplicate_dast_site_tokens_with_same_token_spec.rb b/spec/migrations/remove_duplicate_dast_site_tokens_with_same_token_spec.rb
new file mode 100644
index 00000000000..57d677af5cf
--- /dev/null
+++ b/spec/migrations/remove_duplicate_dast_site_tokens_with_same_token_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require_migration!
+
+RSpec.describe RemoveDuplicateDastSiteTokensWithSameToken do
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+ let(:dast_site_tokens) { table(:dast_site_tokens) }
+ let!(:namespace) { namespaces.create!(id: 1, name: 'group', path: 'group') }
+ let!(:project1) { projects.create!(id: 1, namespace_id: namespace.id, path: 'project1') }
+ # create non duplicate dast site token
+ let!(:dast_site_token1) { dast_site_tokens.create!(project_id: project1.id, url: 'https://gitlab.com', token: SecureRandom.uuid) }
+
+ context 'when duplicate dast site tokens exists' do
+ # create duplicate dast site token
+ let_it_be(:duplicate_token) { 'duplicate_token' }
+ let_it_be(:other_duplicate_token) { 'other_duplicate_token' }
+
+ let!(:project2) { projects.create!(id: 2, namespace_id: namespace.id, path: 'project2') }
+ let!(:dast_site_token2) { dast_site_tokens.create!(project_id: project2.id, url: 'https://gitlab2.com', token: duplicate_token) }
+ let!(:dast_site_token3) { dast_site_tokens.create!(project_id: project2.id, url: 'https://gitlab3.com', token: duplicate_token) }
+ let!(:dast_site_token4) { dast_site_tokens.create!(project_id: project2.id, url: 'https://gitlab4.com', token: duplicate_token) }
+
+ let!(:project3) { projects.create!(id: 3, namespace_id: namespace.id, path: 'project3') }
+ let!(:dast_site_token5) { dast_site_tokens.create!(project_id: project3.id, url: 'https://gitlab2.com', token: other_duplicate_token) }
+ let!(:dast_site_token6) { dast_site_tokens.create!(project_id: project3.id, url: 'https://gitlab3.com', token: other_duplicate_token) }
+ let!(:dast_site_token7) { dast_site_tokens.create!(project_id: project3.id, url: 'https://gitlab4.com', token: other_duplicate_token) }
+
+ describe 'migration up' do
+ it 'does remove duplicated dast site tokens with the same token' do
+ expect(dast_site_tokens.count).to eq(7)
+ expect(dast_site_tokens.where(token: duplicate_token).size).to eq(3)
+
+ migrate!
+
+ expect(dast_site_tokens.count).to eq(3)
+ expect(dast_site_tokens.where(token: duplicate_token).size).to eq(1)
+ end
+ end
+ end
+
+ context 'when duplicate dast site tokens do not exist' do
+ let!(:dast_site_token5) { dast_site_tokens.create!(project_id: 1, url: 'https://gitlab5.com', token: SecureRandom.uuid) }
+
+ describe 'migration up' do
+ it 'does not remove any dast site tokens' do
+ expect { migrate! }.not_to change(dast_site_tokens, :count)
+ end
+ end
+ end
+end
diff --git a/spec/migrations/slice_merge_request_diff_commit_migrations_spec.rb b/spec/migrations/slice_merge_request_diff_commit_migrations_spec.rb
new file mode 100644
index 00000000000..1fd19ee42b4
--- /dev/null
+++ b/spec/migrations/slice_merge_request_diff_commit_migrations_spec.rb
@@ -0,0 +1,69 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration! 'slice_merge_request_diff_commit_migrations'
+
+RSpec.describe SliceMergeRequestDiffCommitMigrations, :migration do
+ let(:migration) { described_class.new }
+
+ describe '#up' do
+ context 'when there are no jobs to process' do
+ it 'does nothing' do
+ expect(migration).not_to receive(:migrate_in)
+ expect(Gitlab::Database::BackgroundMigrationJob).not_to receive(:create!)
+
+ migration.up
+ end
+ end
+
+ context 'when there are pending jobs' do
+ let!(:job1) do
+ Gitlab::Database::BackgroundMigrationJob.create!(
+ class_name: described_class::MIGRATION_CLASS,
+ arguments: [1, 10_001]
+ )
+ end
+
+ let!(:job2) do
+ Gitlab::Database::BackgroundMigrationJob.create!(
+ class_name: described_class::MIGRATION_CLASS,
+ arguments: [10_001, 20_001]
+ )
+ end
+
+ it 'marks the old jobs as finished' do
+ migration.up
+
+ job1.reload
+ job2.reload
+
+ expect(job1).to be_succeeded
+ expect(job2).to be_succeeded
+ end
+
+ it 'the jobs are slices into smaller ranges' do
+ migration.up
+
+ new_jobs = Gitlab::Database::BackgroundMigrationJob
+ .for_migration_class(described_class::MIGRATION_CLASS)
+ .pending
+ .to_a
+
+ expect(new_jobs.map(&:arguments)).to eq([
+ [1, 5_001],
+ [5_001, 10_001],
+ [10_001, 15_001],
+ [15_001, 20_001]
+ ])
+ end
+
+ it 'schedules a background migration for the first job' do
+ expect(migration)
+ .to receive(:migrate_in)
+ .with(1.hour, described_class::STEAL_MIGRATION_CLASS, [1, 5_001])
+
+ migration.up
+ end
+ end
+ end
+end