summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-10-20 08:43:02 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-10-20 08:43:02 +0000
commitd9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch)
tree2341ef426af70ad1e289c38036737e04b0aa5007 /spec/lib/gitlab/background_migration
parentd6e514dd13db8947884cd58fe2a9c2a063400a9b (diff)
downloadgitlab-ce-d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb.tar.gz
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'spec/lib/gitlab/background_migration')
-rw-r--r--spec/lib/gitlab/background_migration/fix_first_mentioned_in_commit_at_spec.rb140
-rw-r--r--spec/lib/gitlab/background_migration/fix_promoted_epics_discussion_ids_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/fix_user_namespace_names_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/fix_user_project_route_names_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/migrate_null_private_profile_to_false_spec.rb23
-rw-r--r--spec/lib/gitlab/background_migration/migrate_pages_metadata_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/populate_merge_request_assignees_table_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/populate_topics_total_projects_count_cache_spec.rb35
8 files changed, 180 insertions, 28 deletions
diff --git a/spec/lib/gitlab/background_migration/fix_first_mentioned_in_commit_at_spec.rb b/spec/lib/gitlab/background_migration/fix_first_mentioned_in_commit_at_spec.rb
new file mode 100644
index 00000000000..d2bfa86f0d1
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/fix_first_mentioned_in_commit_at_spec.rb
@@ -0,0 +1,140 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::BackgroundMigration::FixFirstMentionedInCommitAt, :migration, schema: 20211004110500 do
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+ let(:users) { table(:users) }
+ let(:merge_requests) { table(:merge_requests) }
+ let(:issues) { table(:issues) }
+ let(:issue_metrics) { table(:issue_metrics) }
+ let(:merge_requests_closing_issues) { table(:merge_requests_closing_issues) }
+ let(:diffs) { table(:merge_request_diffs) }
+ let(:ten_days_ago) { 10.days.ago }
+ let(:commits) do
+ table(:merge_request_diff_commits).tap do |t|
+ t.extend(SuppressCompositePrimaryKeyWarning)
+ end
+ end
+
+ let(:namespace) { namespaces.create!(name: 'ns', path: 'ns') }
+ let(:project) { projects.create!(namespace_id: namespace.id) }
+
+ let!(:issue1) do
+ issues.create!(
+ title: 'issue',
+ description: 'description',
+ project_id: project.id
+ )
+ end
+
+ let!(:issue2) do
+ issues.create!(
+ title: 'issue',
+ description: 'description',
+ project_id: project.id
+ )
+ end
+
+ let!(:merge_request1) do
+ merge_requests.create!(
+ source_branch: 'a',
+ target_branch: 'master',
+ target_project_id: project.id
+ )
+ end
+
+ let!(:merge_request2) do
+ merge_requests.create!(
+ source_branch: 'b',
+ target_branch: 'master',
+ target_project_id: project.id
+ )
+ end
+
+ let!(:merge_request_closing_issue1) do
+ merge_requests_closing_issues.create!(issue_id: issue1.id, merge_request_id: merge_request1.id)
+ end
+
+ let!(:merge_request_closing_issue2) do
+ merge_requests_closing_issues.create!(issue_id: issue2.id, merge_request_id: merge_request2.id)
+ end
+
+ let!(:diff1) { diffs.create!(merge_request_id: merge_request1.id) }
+ let!(:diff2) { diffs.create!(merge_request_id: merge_request1.id) }
+
+ let!(:other_diff) { diffs.create!(merge_request_id: merge_request2.id) }
+
+ let!(:commit1) do
+ commits.create!(
+ merge_request_diff_id: diff2.id,
+ relative_order: 0,
+ sha: Gitlab::Database::ShaAttribute.serialize('aaa'),
+ authored_date: 5.days.ago
+ )
+ end
+
+ let!(:commit2) do
+ commits.create!(
+ merge_request_diff_id: diff2.id,
+ relative_order: 1,
+ sha: Gitlab::Database::ShaAttribute.serialize('aaa'),
+ authored_date: 10.days.ago
+ )
+ end
+
+ let!(:commit3) do
+ commits.create!(
+ merge_request_diff_id: other_diff.id,
+ relative_order: 1,
+ sha: Gitlab::Database::ShaAttribute.serialize('aaa'),
+ authored_date: 5.days.ago
+ )
+ end
+
+ def run_migration
+ described_class
+ .new
+ .perform(issue_metrics.minimum(:issue_id), issue_metrics.maximum(:issue_id))
+ end
+
+ it "marks successful slices as completed" do
+ min_issue_id = issue_metrics.minimum(:issue_id)
+ max_issue_id = issue_metrics.maximum(:issue_id)
+
+ expect(subject).to receive(:mark_job_as_succeeded).with(min_issue_id, max_issue_id)
+
+ subject.perform(min_issue_id, max_issue_id)
+ end
+
+ context 'when the persisted first_mentioned_in_commit_at is later than the first commit authored_date' do
+ it 'updates the issue_metrics record' do
+ record1 = issue_metrics.create!(issue_id: issue1.id, first_mentioned_in_commit_at: Time.current)
+ record2 = issue_metrics.create!(issue_id: issue2.id, first_mentioned_in_commit_at: Time.current)
+
+ run_migration
+ record1.reload
+ record2.reload
+
+ expect(record1.first_mentioned_in_commit_at).to be_within(2.seconds).of(commit2.authored_date)
+ expect(record2.first_mentioned_in_commit_at).to be_within(2.seconds).of(commit3.authored_date)
+ end
+ end
+
+ context 'when the persisted first_mentioned_in_commit_at is earlier than the first commit authored_date' do
+ it 'does not update the issue_metrics record' do
+ record = issue_metrics.create!(issue_id: issue1.id, first_mentioned_in_commit_at: 20.days.ago)
+
+ expect { run_migration }.not_to change { record.reload.first_mentioned_in_commit_at }
+ end
+ end
+
+ context 'when the first_mentioned_in_commit_at is null' do
+ it 'does nothing' do
+ record = issue_metrics.create!(issue_id: issue1.id, first_mentioned_in_commit_at: nil)
+
+ expect { run_migration }.not_to change { record.reload.first_mentioned_in_commit_at }
+ end
+ end
+end
diff --git a/spec/lib/gitlab/background_migration/fix_promoted_epics_discussion_ids_spec.rb b/spec/lib/gitlab/background_migration/fix_promoted_epics_discussion_ids_spec.rb
index 452fc962c7b..35ec8be691a 100644
--- a/spec/lib/gitlab/background_migration/fix_promoted_epics_discussion_ids_spec.rb
+++ b/spec/lib/gitlab/background_migration/fix_promoted_epics_discussion_ids_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::BackgroundMigration::FixPromotedEpicsDiscussionIds, schema: 20190715193142 do
+RSpec.describe Gitlab::BackgroundMigration::FixPromotedEpicsDiscussionIds, schema: 20181228175414 do
let(:namespaces) { table(:namespaces) }
let(:users) { table(:users) }
let(:epics) { table(:epics) }
diff --git a/spec/lib/gitlab/background_migration/fix_user_namespace_names_spec.rb b/spec/lib/gitlab/background_migration/fix_user_namespace_names_spec.rb
index 0d0ad2cc39e..95509f9b897 100644
--- a/spec/lib/gitlab/background_migration/fix_user_namespace_names_spec.rb
+++ b/spec/lib/gitlab/background_migration/fix_user_namespace_names_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20190620112608 do
+RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20181228175414 do
let(:namespaces) { table(:namespaces) }
let(:users) { table(:users) }
let(:user) { users.create!(name: "The user's full name", projects_limit: 10, username: 'not-null', email: '1') }
diff --git a/spec/lib/gitlab/background_migration/fix_user_project_route_names_spec.rb b/spec/lib/gitlab/background_migration/fix_user_project_route_names_spec.rb
index 211693d917b..b4444df674e 100644
--- a/spec/lib/gitlab/background_migration/fix_user_project_route_names_spec.rb
+++ b/spec/lib/gitlab/background_migration/fix_user_project_route_names_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::BackgroundMigration::FixUserProjectRouteNames, schema: 20190620112608 do
+RSpec.describe Gitlab::BackgroundMigration::FixUserProjectRouteNames, schema: 20181228175414 do
let(:namespaces) { table(:namespaces) }
let(:users) { table(:users) }
let(:routes) { table(:routes) }
diff --git a/spec/lib/gitlab/background_migration/migrate_null_private_profile_to_false_spec.rb b/spec/lib/gitlab/background_migration/migrate_null_private_profile_to_false_spec.rb
deleted file mode 100644
index 6ff1157cb86..00000000000
--- a/spec/lib/gitlab/background_migration/migrate_null_private_profile_to_false_spec.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::BackgroundMigration::MigrateNullPrivateProfileToFalse, schema: 20190620105427 do
- let(:users) { table(:users) }
-
- it 'correctly migrates nil private_profile to false' do
- private_profile_true = users.create!(private_profile: true, projects_limit: 1, email: 'a@b.com')
- private_profile_false = users.create!(private_profile: false, projects_limit: 1, email: 'b@c.com')
- private_profile_nil = users.create!(private_profile: nil, projects_limit: 1, email: 'c@d.com')
-
- described_class.new.perform(private_profile_true.id, private_profile_nil.id)
-
- private_profile_true.reload
- private_profile_false.reload
- private_profile_nil.reload
-
- expect(private_profile_true.private_profile).to eq(true)
- expect(private_profile_false.private_profile).to eq(false)
- expect(private_profile_nil.private_profile).to eq(false)
- end
-end
diff --git a/spec/lib/gitlab/background_migration/migrate_pages_metadata_spec.rb b/spec/lib/gitlab/background_migration/migrate_pages_metadata_spec.rb
index 815dc2e73e5..b6d93b9ff54 100644
--- a/spec/lib/gitlab/background_migration/migrate_pages_metadata_spec.rb
+++ b/spec/lib/gitlab/background_migration/migrate_pages_metadata_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::BackgroundMigration::MigratePagesMetadata, schema: 20190919040324 do
+RSpec.describe Gitlab::BackgroundMigration::MigratePagesMetadata, schema: 20181228175414 do
let(:projects) { table(:projects) }
subject(:migrate_pages_metadata) { described_class.new }
diff --git a/spec/lib/gitlab/background_migration/populate_merge_request_assignees_table_spec.rb b/spec/lib/gitlab/background_migration/populate_merge_request_assignees_table_spec.rb
index 4e7872a9a1b..1d8eed53553 100644
--- a/spec/lib/gitlab/background_migration/populate_merge_request_assignees_table_spec.rb
+++ b/spec/lib/gitlab/background_migration/populate_merge_request_assignees_table_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::BackgroundMigration::PopulateMergeRequestAssigneesTable, schema: 20190315191339 do
+RSpec.describe Gitlab::BackgroundMigration::PopulateMergeRequestAssigneesTable, schema: 20181228175414 do
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
let(:users) { table(:users) }
diff --git a/spec/lib/gitlab/background_migration/populate_topics_total_projects_count_cache_spec.rb b/spec/lib/gitlab/background_migration/populate_topics_total_projects_count_cache_spec.rb
new file mode 100644
index 00000000000..8e07b43f5b9
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/populate_topics_total_projects_count_cache_spec.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::BackgroundMigration::PopulateTopicsTotalProjectsCountCache, schema: 20211006060436 do
+ it 'correctly populates total projects count cache' do
+ namespaces = table(:namespaces)
+ projects = table(:projects)
+ topics = table(:topics)
+ project_topics = table(:project_topics)
+
+ group = namespaces.create!(name: 'group', path: 'group')
+ project_1 = projects.create!(namespace_id: group.id)
+ project_2 = projects.create!(namespace_id: group.id)
+ project_3 = projects.create!(namespace_id: group.id)
+ topic_1 = topics.create!(name: 'Topic1')
+ topic_2 = topics.create!(name: 'Topic2')
+ topic_3 = topics.create!(name: 'Topic3')
+ topic_4 = topics.create!(name: 'Topic4')
+
+ project_topics.create!(project_id: project_1.id, topic_id: topic_1.id)
+ project_topics.create!(project_id: project_1.id, topic_id: topic_3.id)
+ project_topics.create!(project_id: project_2.id, topic_id: topic_3.id)
+ project_topics.create!(project_id: project_1.id, topic_id: topic_4.id)
+ project_topics.create!(project_id: project_2.id, topic_id: topic_4.id)
+ project_topics.create!(project_id: project_3.id, topic_id: topic_4.id)
+
+ subject.perform(topic_1.id, topic_4.id)
+
+ expect(topic_1.reload.total_projects_count).to eq(1)
+ expect(topic_2.reload.total_projects_count).to eq(0)
+ expect(topic_3.reload.total_projects_count).to eq(2)
+ expect(topic_4.reload.total_projects_count).to eq(3)
+ end
+end