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')
-rw-r--r--spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/migrate_to_hashed_storage_spec.rb43
-rw-r--r--spec/lib/gitlab/background_migration/set_merge_request_diff_files_count_spec.rb19
3 files changed, 59 insertions, 5 deletions
diff --git a/spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb b/spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb
index fad33265030..a23b74bcaca 100644
--- a/spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb
+++ b/spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb
@@ -327,6 +327,6 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat
end
def ls_files(snippet)
- raw_repository(snippet).ls_files(nil)
+ raw_repository(snippet).ls_files(snippet.default_branch)
end
end
diff --git a/spec/lib/gitlab/background_migration/migrate_to_hashed_storage_spec.rb b/spec/lib/gitlab/background_migration/migrate_to_hashed_storage_spec.rb
new file mode 100644
index 00000000000..0f7bb06e830
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/migrate_to_hashed_storage_spec.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+# rubocop:disable RSpec/FactoriesInMigrationSpecs
+RSpec.describe Gitlab::BackgroundMigration::MigrateToHashedStorage, :sidekiq, :redis do
+ let(:migrator) { Gitlab::HashedStorage::Migrator.new }
+
+ subject(:background_migration) { described_class.new }
+
+ describe '#perform' do
+ let!(:project) { create(:project, :empty_repo, :legacy_storage) }
+
+ context 'with pending rollback' do
+ it 'aborts rollback operation' do
+ Sidekiq::Testing.disable! do
+ Sidekiq::Client.push(
+ 'queue' => ::HashedStorage::ProjectRollbackWorker.queue,
+ 'class' => ::HashedStorage::ProjectRollbackWorker,
+ 'args' => [project.id]
+ )
+
+ expect { background_migration.perform }.to change { migrator.rollback_pending? }.from(true).to(false)
+ end
+ end
+ end
+
+ it 'enqueues legacy projects to be migrated' do
+ Sidekiq::Testing.fake! do
+ expect { background_migration.perform }.to change { Sidekiq::Queues[::HashedStorage::MigratorWorker.queue].size }.by(1)
+ end
+ end
+
+ context 'when executing all jobs' do
+ it 'migrates legacy projects' do
+ Sidekiq::Testing.inline! do
+ expect { background_migration.perform }.to change { project.reload.legacy_storage? }.from(true).to(false)
+ end
+ end
+ end
+ end
+end
+# rubocop:enable RSpec/FactoriesInMigrationSpecs
diff --git a/spec/lib/gitlab/background_migration/set_merge_request_diff_files_count_spec.rb b/spec/lib/gitlab/background_migration/set_merge_request_diff_files_count_spec.rb
index 6e9f51f510a..f23518625e4 100644
--- a/spec/lib/gitlab/background_migration/set_merge_request_diff_files_count_spec.rb
+++ b/spec/lib/gitlab/background_migration/set_merge_request_diff_files_count_spec.rb
@@ -13,11 +13,11 @@ RSpec.describe Gitlab::BackgroundMigration::SetMergeRequestDiffFilesCount, schem
let(:project) { projects.create!(namespace_id: namespace.id) }
let(:merge_request) { merge_requests.create!(source_branch: 'x', target_branch: 'master', target_project_id: project.id) }
- it 'fills the files_count column' do
- empty_diff = merge_request_diffs.create!(merge_request_id: merge_request.id)
- filled_diff = merge_request_diffs.create!(merge_request_id: merge_request.id)
+ let!(:empty_diff) { merge_request_diffs.create!(merge_request_id: merge_request.id) }
+ let!(:filled_diff) { merge_request_diffs.create!(merge_request_id: merge_request.id) }
- 3.times do |n|
+ let!(:filled_diff_files) do
+ 1.upto(3).map do |n|
merge_request_diff_files.create!(
merge_request_diff_id: filled_diff.id,
relative_order: n,
@@ -31,10 +31,21 @@ RSpec.describe Gitlab::BackgroundMigration::SetMergeRequestDiffFilesCount, schem
new_path: ''
)
end
+ end
+ it 'fills the files_count column' do
described_class.new.perform(empty_diff.id, filled_diff.id)
expect(empty_diff.reload.files_count).to eq(0)
expect(filled_diff.reload.files_count).to eq(3)
end
+
+ it 'uses the sentinel value if the actual count is too high' do
+ stub_const("#{described_class}::FILES_COUNT_SENTINEL", filled_diff_files.size - 1)
+
+ described_class.new.perform(empty_diff.id, filled_diff.id)
+
+ expect(empty_diff.reload.files_count).to eq(0)
+ expect(filled_diff.reload.files_count).to eq(described_class::FILES_COUNT_SENTINEL)
+ end
end