From b595cb0c1dec83de5bdee18284abe86614bed33b Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 20 Jul 2022 15:40:28 +0000 Subject: Add latest changes from gitlab-org/gitlab@15-2-stable-ee --- spec/tasks/dev_rake_spec.rb | 11 ++++++++-- spec/tasks/gitlab/backup_rake_spec.rb | 39 +++++++++++++---------------------- spec/tasks/gitlab/db_rake_spec.rb | 13 ++++++------ 3 files changed, 30 insertions(+), 33 deletions(-) (limited to 'spec/tasks') diff --git a/spec/tasks/dev_rake_spec.rb b/spec/tasks/dev_rake_spec.rb index fa093db414f..14a5ccfa323 100644 --- a/spec/tasks/dev_rake_spec.rb +++ b/spec/tasks/dev_rake_spec.rb @@ -23,7 +23,7 @@ RSpec.describe 'dev rake tasks' do subject(:setup_task) { run_rake_task('dev:setup') } - let(:connections) { Gitlab::Database.database_base_models.values.map(&:connection) } + let(:connections) { Gitlab::Database.database_base_models_with_gitlab_shared.values.map(&:connection) } it 'sets up the development environment', :aggregate_failures do expect(Rake::Task['gitlab:setup']).to receive(:invoke) @@ -50,8 +50,12 @@ RSpec.describe 'dev rake tasks' do end describe 'terminate_all_connections' do + before do + allow(ActiveRecord::Base).to receive(:clear_all_connections!) + end + let(:connections) do - Gitlab::Database.database_base_models.values.filter_map do |model| + Gitlab::Database.database_base_models_with_gitlab_shared.values.filter_map do |model| model.connection if Gitlab::Database.db_config_share_with(model.connection_db_config).nil? end end @@ -75,6 +79,8 @@ RSpec.describe 'dev rake tasks' do it 'terminates all connections' do expect_connections_to_be_terminated + expect(ActiveRecord::Base).to receive(:clear_all_connections!) + terminate_task end @@ -82,6 +88,7 @@ RSpec.describe 'dev rake tasks' do it 'does not terminate connections' do expect(Rails.env).to receive(:production?).and_return(true) expect_connections_not_to_be_terminated + expect(ActiveRecord::Base).not_to receive(:clear_all_connections!) terminate_task end diff --git a/spec/tasks/gitlab/backup_rake_spec.rb b/spec/tasks/gitlab/backup_rake_spec.rb index 4a3b81a072f..9e914f8202e 100644 --- a/spec/tasks/gitlab/backup_rake_spec.rb +++ b/spec/tasks/gitlab/backup_rake_spec.rb @@ -348,14 +348,16 @@ RSpec.describe 'gitlab:app namespace rake task', :delete 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) + project_snippet_b = create( + :project_snippet, + :repository, + project: project_b, + author: project_b.first_owner, + repository_storage: second_storage_name + ) 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( @@ -400,14 +402,16 @@ RSpec.describe 'gitlab:app namespace rake task', :delete 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) + project_snippet_b = create( + :project_snippet, + :repository, + project: project_b, + author: project_b.first_owner, + repository_storage: second_storage_name + ) 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( @@ -435,21 +439,6 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do 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 diff --git a/spec/tasks/gitlab/db_rake_spec.rb b/spec/tasks/gitlab/db_rake_spec.rb index d8199c09ca1..74bec406947 100644 --- a/spec/tasks/gitlab/db_rake_spec.rb +++ b/spec/tasks/gitlab/db_rake_spec.rb @@ -45,7 +45,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do before do skip_unless_ci_uses_database_tasks - allow(Gitlab::Database).to receive(:database_base_models).and_return(base_models) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(base_models) end it 'marks the migration complete on each database' do @@ -90,7 +90,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do let(:base_models) { { 'main' => main_model } } before do - allow(Gitlab::Database).to receive(:database_base_models).and_return(base_models) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(base_models) end it 'prints a warning message' do @@ -110,7 +110,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do let(:base_models) { { 'main' => main_model } } before do - allow(Gitlab::Database).to receive(:database_base_models).and_return(base_models) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(base_models) end it 'prints an error and exits' do @@ -136,6 +136,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do context 'when geo is not configured' do before do allow(ActiveRecord::Base).to receive_message_chain('configurations.configs_for').and_return([main_config]) + allow(Gitlab::Database).to receive(:has_config?).with(:geo).and_return(false) end context 'when the schema is already loaded' do @@ -260,7 +261,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do before do skip_unless_ci_uses_database_tasks - allow(Gitlab::Database).to receive(:database_base_models).and_return(base_models) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(base_models) end context 'when geo is not configured' do @@ -444,7 +445,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do before do skip_unless_ci_uses_database_tasks - allow(Gitlab::Database).to receive(:database_base_models).and_return(base_models) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(base_models) allow(main_model.connection).to receive(:table_exists?).with('schema_migrations').and_return(true) allow(ci_model.connection).to receive(:table_exists?).with('schema_migrations').and_return(true) @@ -574,7 +575,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do before do skip_if_multiple_databases_not_setup - allow(Gitlab::Database).to receive(:database_base_models).and_return(base_models) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(base_models) end it 'delegates to Gitlab::Database::Reindexing without a specific database' do -- cgit v1.2.1