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/tasks')
-rw-r--r--spec/tasks/dev_rake_spec.rb6
-rw-r--r--spec/tasks/gitlab/artifacts/migrate_rake_spec.rb14
-rw-r--r--spec/tasks/gitlab/backup_rake_spec.rb77
-rw-r--r--spec/tasks/gitlab/db_rake_spec.rb28
4 files changed, 99 insertions, 26 deletions
diff --git a/spec/tasks/dev_rake_spec.rb b/spec/tasks/dev_rake_spec.rb
index 73b1604aa10..fa093db414f 100644
--- a/spec/tasks/dev_rake_spec.rb
+++ b/spec/tasks/dev_rake_spec.rb
@@ -116,7 +116,7 @@ RSpec.describe 'dev rake tasks' do
allow(configurations).to receive(:configs_for).with(env_name: Rails.env, name: 'ci').and_return(ci_configuration)
end
- subject(:load_task) { run_rake_task('dev:setup_ci_db') }
+ subject(:load_task) { run_rake_task('dev:copy_db:ci') }
let(:ci_configuration) { instance_double(ActiveRecord::DatabaseConfigurations::HashConfig, name: 'ci', database: '__test_db_ci') }
@@ -128,14 +128,14 @@ RSpec.describe 'dev rake tasks' do
expect(Rake::Task['dev:terminate_all_connections']).to receive(:invoke)
- run_rake_task('dev:copy_db:ci')
+ load_task
end
context 'when the database already exists' do
it 'prints out a warning' do
expect(ApplicationRecord.connection).to receive(:create_database).and_raise(ActiveRecord::DatabaseAlreadyExists)
- expect { run_rake_task('dev:copy_db:ci') }.to output(/Database '#{ci_configuration.database}' already exists/).to_stderr
+ expect { load_task }.to output(/Database '#{ci_configuration.database}' already exists/).to_stderr
end
end
end
diff --git a/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb b/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb
index 25a3723fbaa..1c8a1c6a171 100644
--- a/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb
+++ b/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb
@@ -17,7 +17,7 @@ RSpec.describe 'gitlab:artifacts namespace rake task', :silence_stdout do
subject { run_rake_task('gitlab:artifacts:migrate') }
let!(:artifact) { create(:ci_job_artifact, :archive, file_store: store) }
- let!(:job_trace) { create(:ci_job_artifact, :trace, file_store: store) }
+ let!(:job_log) { create(:ci_job_artifact, :trace, file_store: store) }
context 'when local storage is used' do
let(:store) { ObjectStorage::Store::LOCAL }
@@ -29,7 +29,7 @@ RSpec.describe 'gitlab:artifacts namespace rake task', :silence_stdout do
subject
expect(artifact.reload.file_store).to eq(ObjectStorage::Store::REMOTE)
- expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::REMOTE)
+ expect(job_log.reload.file_store).to eq(ObjectStorage::Store::REMOTE)
end
end
@@ -38,7 +38,7 @@ RSpec.describe 'gitlab:artifacts namespace rake task', :silence_stdout do
subject
expect(artifact.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
- expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
+ expect(job_log.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
end
end
end
@@ -51,7 +51,7 @@ RSpec.describe 'gitlab:artifacts namespace rake task', :silence_stdout do
subject
expect(artifact.reload.file_store).to eq(ObjectStorage::Store::REMOTE)
- expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::REMOTE)
+ expect(job_log.reload.file_store).to eq(ObjectStorage::Store::REMOTE)
end
end
end
@@ -62,7 +62,7 @@ RSpec.describe 'gitlab:artifacts namespace rake task', :silence_stdout do
subject { run_rake_task('gitlab:artifacts:migrate_to_local') }
let!(:artifact) { create(:ci_job_artifact, :archive, file_store: store) }
- let!(:job_trace) { create(:ci_job_artifact, :trace, file_store: store) }
+ let!(:job_log) { create(:ci_job_artifact, :trace, file_store: store) }
context 'when remote storage is used' do
let(:store) { ObjectStorage::Store::REMOTE }
@@ -72,7 +72,7 @@ RSpec.describe 'gitlab:artifacts namespace rake task', :silence_stdout do
subject
expect(artifact.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
- expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
+ expect(job_log.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
end
end
end
@@ -84,7 +84,7 @@ RSpec.describe 'gitlab:artifacts namespace rake task', :silence_stdout do
subject
expect(artifact.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
- expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
+ expect(job_log.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
end
end
end
diff --git a/spec/tasks/gitlab/backup_rake_spec.rb b/spec/tasks/gitlab/backup_rake_spec.rb
index 6080948403d..52a0a9a7385 100644
--- a/spec/tasks/gitlab/backup_rake_spec.rb
+++ b/spec/tasks/gitlab/backup_rake_spec.rb
@@ -377,21 +377,6 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do
expect(tar_lines).to include(a_string_matching(repo_name))
end
end
-
- def move_repository_to_secondary(record)
- Gitlab::GitalyClient::StorageSettings.allow_disk_access do
- default_shard_legacy_path = Gitlab.config.repositories.storages.default.legacy_disk_path
- secondary_legacy_path = Gitlab.config.repositories.storages[second_storage_name].legacy_disk_path
- dst_dir = File.join(secondary_legacy_path, File.dirname(record.disk_path))
-
- FileUtils.mkdir_p(dst_dir) unless Dir.exist?(dst_dir)
-
- FileUtils.mv(
- File.join(default_shard_legacy_path, record.disk_path + '.git'),
- File.join(secondary_legacy_path, record.disk_path + '.git')
- )
- end
- end
end
context 'no concurrency' do
@@ -405,6 +390,66 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do
it_behaves_like 'includes repositories in all repository storages'
end
+
+ context 'REPOSITORIES_STORAGES set' do
+ before do
+ stub_env('REPOSITORIES_STORAGES', default_storage_name)
+ end
+
+ it 'includes repositories in default repository storage', :aggregate_failures do
+ project_a = create(:project, :repository)
+ project_snippet_a = create(:project_snippet, :repository, project: project_a, author: project_a.first_owner)
+ project_b = create(:project, :repository, repository_storage: second_storage_name)
+ project_snippet_b = create(:project_snippet, :repository, project: project_b, author: project_b.first_owner)
+ project_snippet_b.snippet_repository.update!(shard: project_b.project_repository.shard)
+ create(:wiki_page, container: project_a)
+ create(:design, :with_file, issue: create(:issue, project: project_a))
+
+ move_repository_to_secondary(project_b)
+ move_repository_to_secondary(project_snippet_b)
+
+ expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout_from_any_process
+
+ tar_contents, exit_status = Gitlab::Popen.popen(
+ %W{tar -tvf #{backup_tar} repositories}
+ )
+
+ tar_lines = tar_contents.lines.grep(/\.bundle/)
+
+ expect(exit_status).to eq(0)
+
+ [
+ "#{project_a.disk_path}/.+/001.bundle",
+ "#{project_a.disk_path}.wiki/.+/001.bundle",
+ "#{project_a.disk_path}.design/.+/001.bundle",
+ "#{project_snippet_a.disk_path}/.+/001.bundle"
+ ].each do |repo_name|
+ expect(tar_lines).to include(a_string_matching(repo_name))
+ end
+
+ [
+ "#{project_b.disk_path}/.+/001.bundle",
+ "#{project_snippet_b.disk_path}/.+/001.bundle"
+ ].each do |repo_name|
+ expect(tar_lines).not_to include(a_string_matching(repo_name))
+ end
+ end
+ end
+
+ def move_repository_to_secondary(record)
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ default_shard_legacy_path = Gitlab.config.repositories.storages.default.legacy_disk_path
+ secondary_legacy_path = Gitlab.config.repositories.storages[second_storage_name].legacy_disk_path
+ dst_dir = File.join(secondary_legacy_path, File.dirname(record.disk_path))
+
+ FileUtils.mkdir_p(dst_dir) unless Dir.exist?(dst_dir)
+
+ FileUtils.mv(
+ File.join(default_shard_legacy_path, record.disk_path + '.git'),
+ File.join(secondary_legacy_path, record.disk_path + '.git')
+ )
+ end
+ end
end
context 'concurrency settings' do
@@ -420,7 +465,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do
stub_env('GITLAB_BACKUP_MAX_STORAGE_CONCURRENCY', 2)
expect(::Backup::Repositories).to receive(:new)
- .with(anything, strategy: anything)
+ .with(anything, strategy: anything, storages: [])
.and_call_original
expect(::Backup::GitalyBackup).to receive(:new).with(anything, max_parallelism: 5, storage_parallelism: 2, incremental: false).and_call_original
diff --git a/spec/tasks/gitlab/db_rake_spec.rb b/spec/tasks/gitlab/db_rake_spec.rb
index 73f3b55e12e..e340d568269 100644
--- a/spec/tasks/gitlab/db_rake_spec.rb
+++ b/spec/tasks/gitlab/db_rake_spec.rb
@@ -697,6 +697,34 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
run_rake_task('gitlab:db:migration_testing:sample_background_migrations', '[100]')
end
end
+
+ describe '#sample_batched_background_migrations' do
+ let(:batched_runner) { instance_double(::Gitlab::Database::Migrations::TestBatchedBackgroundRunner) }
+
+ it 'delegates to the migration runner for the main database with a default sample duration' do
+ expect(::Gitlab::Database::Migrations::Runner).to receive(:batched_background_migrations)
+ .with(for_database: 'main').and_return(batched_runner)
+ expect(batched_runner).to receive(:run_jobs).with(for_duration: 30.minutes)
+
+ run_rake_task('gitlab:db:migration_testing:sample_batched_background_migrations')
+ end
+
+ it 'delegates to the migration runner for a specified database with a default sample duration' do
+ expect(::Gitlab::Database::Migrations::Runner).to receive(:batched_background_migrations)
+ .with(for_database: 'ci').and_return(batched_runner)
+ expect(batched_runner).to receive(:run_jobs).with(for_duration: 30.minutes)
+
+ run_rake_task('gitlab:db:migration_testing:sample_batched_background_migrations', '[ci]')
+ end
+
+ it 'delegates to the migration runner for a specified database and sample duration' do
+ expect(::Gitlab::Database::Migrations::Runner).to receive(:batched_background_migrations)
+ .with(for_database: 'ci').and_return(batched_runner)
+ expect(batched_runner).to receive(:run_jobs).with(for_duration: 100.seconds)
+
+ run_rake_task('gitlab:db:migration_testing:sample_batched_background_migrations', '[ci, 100]')
+ end
+ end
end
describe '#execute_batched_migrations' do