diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 18:25:58 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 18:25:58 +0000 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /spec/tasks | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) | |
download | gitlab-ce-a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4.tar.gz |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/tasks')
41 files changed, 156 insertions, 94 deletions
diff --git a/spec/tasks/admin_mode_spec.rb b/spec/tasks/admin_mode_spec.rb index 9dd35650ab6..116d47aa503 100644 --- a/spec/tasks/admin_mode_spec.rb +++ b/spec/tasks/admin_mode_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'admin mode on tasks' do +RSpec.describe 'admin mode on tasks', :silence_stdout do before do allow(::Gitlab::Runtime).to receive(:test_suite?).and_return(false) allow(::Gitlab::Runtime).to receive(:rake?).and_return(true) diff --git a/spec/tasks/cache/clear/redis_spec.rb b/spec/tasks/cache/clear/redis_spec.rb index d2de068f254..64ed83c649b 100644 --- a/spec/tasks/cache/clear/redis_spec.rb +++ b/spec/tasks/cache/clear/redis_spec.rb @@ -2,11 +2,15 @@ require 'rake_helper' -RSpec.describe 'clearing redis cache' do +RSpec.describe 'clearing redis cache', :clean_gitlab_redis_cache, :silence_stdout do before do Rake.application.rake_require 'tasks/cache' end + shared_examples 'clears the cache' do + it { expect { run_rake_task('cache:clear:redis') }.to change { redis_keys.size }.by(-1) } + end + describe 'clearing pipeline status cache' do let(:pipeline_status) do project = create(:project, :repository) @@ -20,5 +24,38 @@ RSpec.describe 'clearing redis cache' do it 'clears pipeline status cache' do expect { run_rake_task('cache:clear:redis') }.to change { pipeline_status.has_cache? } end + + it_behaves_like 'clears the cache' + end + + describe 'clearing set caches' do + context 'repository set' do + let(:project) { create(:project) } + let(:repository) { project.repository } + + let(:cache) { Gitlab::RepositorySetCache.new(repository) } + + before do + pending "Enable as part of https://gitlab.com/gitlab-org/gitlab/-/issues/331319" + + cache.write(:foo, [:bar]) + end + + it_behaves_like 'clears the cache' + end + + context 'reactive cache set' do + let(:cache) { Gitlab::ReactiveCacheSetCache.new } + + before do + cache.write(:foo, :bar) + end + + it_behaves_like 'clears the cache' + end + end + + def redis_keys + Gitlab::Redis::Cache.with { |redis| redis.scan(0, match: "*") }.last end end diff --git a/spec/tasks/config_lint_spec.rb b/spec/tasks/config_lint_spec.rb index f5a382989ea..34899c84888 100644 --- a/spec/tasks/config_lint_spec.rb +++ b/spec/tasks/config_lint_spec.rb @@ -3,7 +3,7 @@ require 'rake_helper' Rake.application.rake_require 'tasks/config_lint' -RSpec.describe ConfigLint do +RSpec.describe ConfigLint, :silence_stdout do let(:files) { ['lib/support/fake.sh'] } it 'errors out if any bash scripts have errors' do @@ -15,7 +15,7 @@ RSpec.describe ConfigLint do end end -RSpec.describe 'config_lint rake task' do +RSpec.describe 'config_lint rake task', :silence_stdout do before do # Prevent `system` from actually being called allow(Kernel).to receive(:system).and_return(true) diff --git a/spec/tasks/gettext_rake_spec.rb b/spec/tasks/gettext_rake_spec.rb index a535ac92a75..29caa363f7b 100644 --- a/spec/tasks/gettext_rake_spec.rb +++ b/spec/tasks/gettext_rake_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require "rake_helper" +require 'rake_helper' -RSpec.describe 'gettext' do +RSpec.describe 'gettext', :silence_stdout do let(:locale_path) { Rails.root.join('tmp/gettext_spec') } let(:pot_file_path) { File.join(locale_path, 'gitlab.pot') } diff --git a/spec/tasks/gitlab/artifacts/check_rake_spec.rb b/spec/tasks/gitlab/artifacts/check_rake_spec.rb index d1d02ab9bc5..e0303170755 100644 --- a/spec/tasks/gitlab/artifacts/check_rake_spec.rb +++ b/spec/tasks/gitlab/artifacts/check_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:artifacts rake tasks' do +RSpec.describe 'gitlab:artifacts rake tasks', :silence_stdout do describe 'check' do let!(:artifact) { create(:ci_job_artifact, :archive, :correct_checksum) } diff --git a/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb b/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb index 94a8da9478a..25a3723fbaa 100644 --- a/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb +++ b/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:artifacts namespace rake task' do +RSpec.describe 'gitlab:artifacts namespace rake task', :silence_stdout do before(:context) do Rake.application.rake_require 'tasks/gitlab/artifacts/migrate' end diff --git a/spec/tasks/gitlab/backup_rake_spec.rb b/spec/tasks/gitlab/backup_rake_spec.rb index 8963164ac53..e5a210bb344 100644 --- a/spec/tasks/gitlab/backup_rake_spec.rb +++ b/spec/tasks/gitlab/backup_rake_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' -require 'rake' +require 'rake_helper' RSpec.describe 'gitlab:app namespace rake task', :delete do let(:enable_registry) { true } @@ -24,14 +23,10 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do before(:all) do Rake.application.rake_require 'active_record/railties/databases' - Rake.application.rake_require 'tasks/gitlab/helpers' Rake.application.rake_require 'tasks/gitlab/backup' Rake.application.rake_require 'tasks/gitlab/shell' Rake.application.rake_require 'tasks/gitlab/db' Rake.application.rake_require 'tasks/cache' - - # empty task as env is already loaded - Rake::Task.define_task :environment end before do @@ -39,6 +34,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do FileUtils.rm(tars_glob, force: true) FileUtils.rm(backup_files, force: true) FileUtils.rm_rf(backup_directories, secure: true) + FileUtils.mkdir_p('tmp/tests/public/uploads') reenable_backup_sub_tasks stub_container_registry_config(enabled: enable_registry) end @@ -47,12 +43,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do FileUtils.rm(tars_glob, force: true) FileUtils.rm(backup_files, force: true) FileUtils.rm_rf(backup_directories, secure: true) - end - - def run_rake_task(task_name) - FileUtils.mkdir_p('tmp/tests/public/uploads') - Rake::Task[task_name].reenable - Rake.application.invoke_task task_name + FileUtils.rm_rf('tmp/tests/public/uploads', secure: true) end def reenable_backup_sub_tasks @@ -92,11 +83,11 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do end it 'invokes restoration on match' do - expect { run_rake_task('gitlab:backup:restore') }.to output.to_stdout + expect { run_rake_task('gitlab:backup:restore') }.to output.to_stdout_from_any_process end it 'prints timestamps on messages' do - expect { run_rake_task('gitlab:backup:restore') }.to output(/.*\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\s[-+]\d{4}\s--\s.*/).to_stdout + expect { run_rake_task('gitlab:backup:restore') }.to output(/.*\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\s[-+]\d{4}\s--\s.*/).to_stdout_from_any_process end end end @@ -105,14 +96,16 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do before do # We only need a backup of the repositories for this test stub_env('SKIP', 'db,uploads,builds,artifacts,lfs,registry') + + create(:project, :repository) end it 'removes stale data' do - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout + expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout_from_any_process excluded_project = create(:project, :repository, name: 'mepmep') - expect { run_rake_task('gitlab:backup:restore') }.to output.to_stdout + expect { run_rake_task('gitlab:backup:restore') }.to output.to_stdout_from_any_process raw_repo = excluded_project.repository.raw @@ -124,9 +117,10 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do context 'when the backup is restored' do let!(:included_project) { create(:project, :repository) } + let!(:original_checksum) { included_project.repository.checksum } before do - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout + expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout_from_any_process backup_tar = Dir.glob(File.join(Gitlab.config.backup.path, '*_gitlab_backup.tar')).last allow(Dir).to receive(:glob).and_return([backup_tar]) @@ -153,11 +147,12 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do end it 'restores the data' do - expect { run_rake_task('gitlab:backup:restore') }.to output.to_stdout + expect { run_rake_task('gitlab:backup:restore') }.to output.to_stdout_from_any_process raw_repo = included_project.repository.raw expect(raw_repo.empty?).to be(false) + expect(included_project.repository.checksum).to eq(original_checksum) end end end @@ -169,8 +164,9 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do allow(ActiveRecord::Base.connection).to receive(:reconnect!) end + let!(:project) { create(:project, :repository) } + describe 'backup creation and deletion using custom_hooks' do - let(:project) { create(:project, :repository) } let(:user_backup_path) { "repositories/#{project.disk_path}" } before do @@ -184,7 +180,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do context 'project uses custom_hooks and successfully creates backup' do it 'creates custom_hooks.tar and project bundle' do - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout + 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}}) @@ -195,8 +191,8 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do end it 'restores files correctly' do - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout - expect { run_rake_task('gitlab:backup:restore') }.to output.to_stdout + expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout_from_any_process + expect { run_rake_task('gitlab:backup:restore') }.to output.to_stdout_from_any_process repo_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do project.repository.path @@ -210,7 +206,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do it 'prints a progress message to stdout' do task_list.each do |task| - expect { run_rake_task("gitlab:backup:#{task}:create") }.to output(/Dumping /).to_stdout + expect { run_rake_task("gitlab:backup:#{task}:create") }.to output(/Dumping /).to_stdout_from_any_process end end end @@ -219,7 +215,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do context 'tar creation' do context 'archive file permissions' do it 'sets correct permissions on the tar file' do - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout + expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout_from_any_process expect(File.exist?(backup_tar)).to be_truthy expect(File::Stat.new(backup_tar).mode.to_s(8)).to eq('100600') @@ -231,7 +227,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do end it 'uses the custom permissions' do - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout + expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout_from_any_process expect(File::Stat.new(backup_tar).mode.to_s(8)).to eq('100651') end @@ -239,7 +235,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do end it 'sets correct permissions on the tar contents' do - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout + 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} db uploads.tar.gz repositories builds.tar.gz artifacts.tar.gz pages.tar.gz lfs.tar.gz registry.tar.gz} @@ -258,7 +254,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do end it 'deletes temp directories' do - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout + expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout_from_any_process temp_dirs = Dir.glob( File.join(Gitlab.config.backup.path, '{db,repositories,uploads,builds,artifacts,pages,lfs,registry}') @@ -271,7 +267,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do let(:enable_registry) { false } it 'does not create registry.tar.gz' do - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout + 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}} @@ -301,10 +297,8 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do shared_examples 'includes repositories in all repository storages' do specify :aggregate_failures do project_a = create(:project, :repository) - project_a.track_project_repository project_snippet_a = create(:project_snippet, :repository, project: project_a, author: project_a.owner) project_b = create(:project, :repository, repository_storage: second_storage_name) - project_b.track_project_repository project_snippet_b = create(:project_snippet, :repository, project: project_b, author: project_b.owner) project_snippet_b.snippet_repository.update!(shard: project_b.project_repository.shard) create(:wiki_page, container: project_a) @@ -313,7 +307,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do move_repository_to_secondary(project_b) move_repository_to_secondary(project_snippet_b) - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout + 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} @@ -379,7 +373,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do .and_call_original end - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout + expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout_from_any_process end it 'passes through concurrency environment variables' do @@ -392,7 +386,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do .and_call_original end - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout + expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout_from_any_process end end end @@ -401,10 +395,12 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do describe "Skipping items" do before do stub_env('SKIP', 'repositories,uploads') + + create(:project, :repository) end it "does not contain skipped item" do - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout + 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} db uploads.tar.gz repositories builds.tar.gz artifacts.tar.gz pages.tar.gz lfs.tar.gz registry.tar.gz} @@ -421,7 +417,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do end it 'does not invoke repositories restore' do - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout + expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout_from_any_process allow(Rake::Task['gitlab:shell:setup']) .to receive(:invoke).and_return(true) @@ -436,17 +432,19 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do expect(Rake::Task['gitlab:backup:lfs:restore']).to receive :invoke expect(Rake::Task['gitlab:backup:registry:restore']).to receive :invoke expect(Rake::Task['gitlab:shell:setup']).to receive :invoke - expect { run_rake_task('gitlab:backup:restore') }.to output.to_stdout + expect { run_rake_task('gitlab:backup:restore') }.to output.to_stdout_from_any_process end end describe 'skipping tar archive creation' do before do stub_env('SKIP', 'tar') + + create(:project, :repository) end it 'created files with backup content and no tar archive' do - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout + expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout_from_any_process dir_contents = Dir.children(Gitlab.config.backup.path) @@ -465,7 +463,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do end it 'those component files can be restored from' do - expect { run_rake_task("gitlab:backup:create") }.to output.to_stdout + expect { run_rake_task("gitlab:backup:create") }.to output.to_stdout_from_any_process allow(Rake::Task['gitlab:shell:setup']) .to receive(:invoke).and_return(true) @@ -480,13 +478,13 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do expect(Rake::Task['gitlab:backup:lfs:restore']).to receive :invoke expect(Rake::Task['gitlab:backup:registry:restore']).to receive :invoke expect(Rake::Task['gitlab:shell:setup']).to receive :invoke - expect { run_rake_task("gitlab:backup:restore") }.to output.to_stdout + expect { run_rake_task("gitlab:backup:restore") }.to output.to_stdout_from_any_process end end describe "Human Readable Backup Name" do it 'name has human readable time' do - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout + expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout_from_any_process expect(backup_tar).to match(/\d+_\d{4}_\d{2}_\d{2}_\d+\.\d+\.\d+.*_gitlab_backup.tar$/) end diff --git a/spec/tasks/gitlab/check_rake_spec.rb b/spec/tasks/gitlab/check_rake_spec.rb index 7956b5c57e6..aee03059120 100644 --- a/spec/tasks/gitlab/check_rake_spec.rb +++ b/spec/tasks/gitlab/check_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'check.rake' do +RSpec.describe 'check.rake', :silence_stdout do before do Rake.application.rake_require 'tasks/gitlab/check' diff --git a/spec/tasks/gitlab/cleanup_rake_spec.rb b/spec/tasks/gitlab/cleanup_rake_spec.rb index 08d8651dcef..16c907ca87c 100644 --- a/spec/tasks/gitlab/cleanup_rake_spec.rb +++ b/spec/tasks/gitlab/cleanup_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:cleanup rake tasks' do +RSpec.describe 'gitlab:cleanup rake tasks', :silence_stdout do before do Rake.application.rake_require 'tasks/gitlab/cleanup' end diff --git a/spec/tasks/gitlab/container_registry_rake_spec.rb b/spec/tasks/gitlab/container_registry_rake_spec.rb index b83ff567126..f19e93fc6cb 100644 --- a/spec/tasks/gitlab/container_registry_rake_spec.rb +++ b/spec/tasks/gitlab/container_registry_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:container_registry namespace rake tasks' do +RSpec.describe 'gitlab:container_registry namespace rake tasks', :silence_stdout do let_it_be(:api_url) { 'http://registry.gitlab' } before :all do diff --git a/spec/tasks/gitlab/db_rake_spec.rb b/spec/tasks/gitlab/db_rake_spec.rb index c4623061944..08ca6c32b49 100644 --- a/spec/tasks/gitlab/db_rake_spec.rb +++ b/spec/tasks/gitlab/db_rake_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require 'rake' -RSpec.describe 'gitlab:db namespace rake task' do +RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do before :all do Rake.application.rake_require 'active_record/railties/databases' Rake.application.rake_require 'tasks/seed_fu' @@ -306,7 +306,7 @@ RSpec.describe 'gitlab:db namespace rake task' do let(:all_migrations) { [double('migration1', version: 1), pending_migration] } let(:pending_migration) { double('migration2', version: 2) } let(:filename) { Gitlab::Database::Migrations::Instrumentation::STATS_FILENAME } - let!(:directory) { Dir.mktmpdir } + let(:result_dir) { Dir.mktmpdir } let(:observations) { %w[some data] } before do @@ -316,19 +316,17 @@ RSpec.describe 'gitlab:db namespace rake task' do allow(instrumentation).to receive(:observe).and_yield - allow(Dir).to receive(:mkdir) - allow(File).to receive(:exist?).with(directory).and_return(false) - stub_const('Gitlab::Database::Migrations::Instrumentation::RESULT_DIR', directory) + stub_const('Gitlab::Database::Migrations::Instrumentation::RESULT_DIR', result_dir) end after do - FileUtils.rm_rf([directory]) + FileUtils.rm_rf(result_dir) end - it 'fails when the directory already exists' do - expect(File).to receive(:exist?).with(directory).and_return(true) + it 'creates result directory when one does not exist' do + FileUtils.rm_rf(result_dir) - expect { subject }.to raise_error(/Directory exists/) + expect { subject }.to change { Dir.exist?(result_dir) }.from(false).to(true) end it 'instruments the pending migration' do @@ -346,7 +344,7 @@ RSpec.describe 'gitlab:db namespace rake task' do it 'writes observations out to JSON file' do subject - expect(File.read(File.join(directory, filename))).to eq(observations.to_json) + expect(File.read(File.join(result_dir, filename))).to eq(observations.to_json) end end diff --git a/spec/tasks/gitlab/external_diffs_rake_spec.rb b/spec/tasks/gitlab/external_diffs_rake_spec.rb index 66e555734b3..86242de4b90 100644 --- a/spec/tasks/gitlab/external_diffs_rake_spec.rb +++ b/spec/tasks/gitlab/external_diffs_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:external_diffs rake tasks' do +RSpec.describe 'gitlab:external_diffs rake tasks', :silence_stdout do before do Rake.application.rake_require 'tasks/gitlab/external_diffs' end diff --git a/spec/tasks/gitlab/generate_sample_prometheus_data_spec.rb b/spec/tasks/gitlab/generate_sample_prometheus_data_spec.rb index a8effef2d7b..67bf512c6da 100644 --- a/spec/tasks/gitlab/generate_sample_prometheus_data_spec.rb +++ b/spec/tasks/gitlab/generate_sample_prometheus_data_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:generate_sample_prometheus_data rake task' do +RSpec.describe 'gitlab:generate_sample_prometheus_data rake task', :silence_stdout do let(:cluster) { create(:cluster, :provided_by_user, :project) } let(:environment) { create(:environment, project: cluster.project) } let(:sample_query_file) { File.join(Rails.root, Metrics::SampleMetricsService::DIRECTORY, 'test_query_result.yml') } diff --git a/spec/tasks/gitlab/git_rake_spec.rb b/spec/tasks/gitlab/git_rake_spec.rb index 50ec2632d83..aab927a472e 100644 --- a/spec/tasks/gitlab/git_rake_spec.rb +++ b/spec/tasks/gitlab/git_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:git rake tasks' do +RSpec.describe 'gitlab:git rake tasks', :silence_stdout do let(:base_path) { 'tmp/tests/default_storage' } let!(:project) { create(:project, :repository) } diff --git a/spec/tasks/gitlab/gitaly_rake_spec.rb b/spec/tasks/gitlab/gitaly_rake_spec.rb index 1b38580f484..5adea832995 100644 --- a/spec/tasks/gitlab/gitaly_rake_spec.rb +++ b/spec/tasks/gitlab/gitaly_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:gitaly namespace rake task' do +RSpec.describe 'gitlab:gitaly namespace rake task', :silence_stdout do before :all do Rake.application.rake_require 'tasks/gitlab/gitaly' end diff --git a/spec/tasks/gitlab/info_rake_spec.rb b/spec/tasks/gitlab/info_rake_spec.rb index 941f3429017..19ed43723e2 100644 --- a/spec/tasks/gitlab/info_rake_spec.rb +++ b/spec/tasks/gitlab/info_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:env:info' do +RSpec.describe 'gitlab:env:info', :silence_stdout do before do Rake.application.rake_require 'tasks/gitlab/info' diff --git a/spec/tasks/gitlab/ldap_rake_spec.rb b/spec/tasks/gitlab/ldap_rake_spec.rb index 5286cd98944..693bb7826a3 100644 --- a/spec/tasks/gitlab/ldap_rake_spec.rb +++ b/spec/tasks/gitlab/ldap_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:ldap:rename_provider rake task' do +RSpec.describe 'gitlab:ldap:rename_provider rake task', :silence_stdout do it 'completes without error' do Rake.application.rake_require 'tasks/gitlab/ldap' stub_warn_user_is_not_gitlab @@ -93,8 +93,8 @@ RSpec.describe 'gitlab:ldap:secret rake tasks' do describe 'write' do before do - allow(STDIN).to receive(:tty?).and_return(false) - allow(STDIN).to receive(:read).and_return('testvalue') + allow($stdin).to receive(:tty?).and_return(false) + allow($stdin).to receive(:read).and_return('testvalue') end it 'creates encrypted file from stdin' do diff --git a/spec/tasks/gitlab/lfs/check_rake_spec.rb b/spec/tasks/gitlab/lfs/check_rake_spec.rb index fd1b6d010e4..ce0076826c4 100644 --- a/spec/tasks/gitlab/lfs/check_rake_spec.rb +++ b/spec/tasks/gitlab/lfs/check_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:lfs rake tasks' do +RSpec.describe 'gitlab:lfs rake tasks', :silence_stdout do describe 'check' do let!(:lfs_object) { create(:lfs_object, :with_file, :correct_oid) } diff --git a/spec/tasks/gitlab/lfs/migrate_rake_spec.rb b/spec/tasks/gitlab/lfs/migrate_rake_spec.rb index a59da615b94..3b571507bac 100644 --- a/spec/tasks/gitlab/lfs/migrate_rake_spec.rb +++ b/spec/tasks/gitlab/lfs/migrate_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:lfs namespace rake task' do +RSpec.describe 'gitlab:lfs namespace rake task', :silence_stdout do before :all do Rake.application.rake_require 'tasks/gitlab/lfs/migrate' end diff --git a/spec/tasks/gitlab/packages/composer_rake_spec.rb b/spec/tasks/gitlab/packages/composer_rake_spec.rb index d54e1b02599..78013714de5 100644 --- a/spec/tasks/gitlab/packages/composer_rake_spec.rb +++ b/spec/tasks/gitlab/packages/composer_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:packages:build_composer_cache namespace rake task' do +RSpec.describe 'gitlab:packages:build_composer_cache namespace rake task', :silence_stdout do let_it_be(:package_name) { 'sample-project' } let_it_be(:package_name2) { 'sample-project2' } let_it_be(:json) { { 'name' => package_name } } diff --git a/spec/tasks/gitlab/packages/events_rake_spec.rb b/spec/tasks/gitlab/packages/events_rake_spec.rb index d6aa6deac1e..87f4db360ca 100644 --- a/spec/tasks/gitlab/packages/events_rake_spec.rb +++ b/spec/tasks/gitlab/packages/events_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:packages:events namespace rake task' do +RSpec.describe 'gitlab:packages:events namespace rake task', :silence_stdout do before :all do Rake.application.rake_require 'tasks/gitlab/packages/events' end diff --git a/spec/tasks/gitlab/packages/migrate_rake_spec.rb b/spec/tasks/gitlab/packages/migrate_rake_spec.rb index 618ff215c74..bf34034ee57 100644 --- a/spec/tasks/gitlab/packages/migrate_rake_spec.rb +++ b/spec/tasks/gitlab/packages/migrate_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:packages namespace rake task' do +RSpec.describe 'gitlab:packages namespace rake task', :silence_stdout do before :all do Rake.application.rake_require 'tasks/gitlab/packages/migrate' end diff --git a/spec/tasks/gitlab/pages_rake_spec.rb b/spec/tasks/gitlab/pages_rake_spec.rb index 664899c361b..d4bfcafa7b4 100644 --- a/spec/tasks/gitlab/pages_rake_spec.rb +++ b/spec/tasks/gitlab/pages_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:pages' do +RSpec.describe 'gitlab:pages', :silence_stdout do before(:context) do Rake.application.rake_require 'tasks/gitlab/pages' end diff --git a/spec/tasks/gitlab/password_rake_spec.rb b/spec/tasks/gitlab/password_rake_spec.rb index d5320f3b4af..65bba836024 100644 --- a/spec/tasks/gitlab/password_rake_spec.rb +++ b/spec/tasks/gitlab/password_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:password rake tasks' do +RSpec.describe 'gitlab:password rake tasks', :silence_stdout do let_it_be(:user_1) { create(:user, username: 'foobar', password: 'initial_password') } def stub_username(username) diff --git a/spec/tasks/gitlab/praefect_rake_spec.rb b/spec/tasks/gitlab/praefect_rake_spec.rb index c67dba110c7..85e655ed72c 100644 --- a/spec/tasks/gitlab/praefect_rake_spec.rb +++ b/spec/tasks/gitlab/praefect_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:praefect:replicas' do +RSpec.describe 'gitlab:praefect:replicas', :silence_stdout do before do Rake.application.rake_require 'tasks/gitlab/praefect' end diff --git a/spec/tasks/gitlab/seed/group_seed_rake_spec.rb b/spec/tasks/gitlab/seed/group_seed_rake_spec.rb index 0b69615eebc..2f57e875f5f 100644 --- a/spec/tasks/gitlab/seed/group_seed_rake_spec.rb +++ b/spec/tasks/gitlab/seed/group_seed_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:seed:group_seed rake task' do +RSpec.describe 'gitlab:seed:group_seed rake task', :silence_stdout do let(:username) { 'group_seed' } let!(:user) { create(:user, username: username) } let(:task_params) { [2, username] } diff --git a/spec/tasks/gitlab/shell_rake_spec.rb b/spec/tasks/gitlab/shell_rake_spec.rb index a929daddb67..52a9738fb51 100644 --- a/spec/tasks/gitlab/shell_rake_spec.rb +++ b/spec/tasks/gitlab/shell_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:shell rake tasks' do +RSpec.describe 'gitlab:shell rake tasks', :silence_stdout do before do Rake.application.rake_require 'tasks/gitlab/shell' diff --git a/spec/tasks/gitlab/sidekiq_rake_spec.rb b/spec/tasks/gitlab/sidekiq_rake_spec.rb index 61a8aecfa61..75f904389e2 100644 --- a/spec/tasks/gitlab/sidekiq_rake_spec.rb +++ b/spec/tasks/gitlab/sidekiq_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'sidekiq.rake', :aggregate_failures do +RSpec.describe 'sidekiq.rake', :aggregate_failures, :silence_stdout do before do Rake.application.rake_require 'tasks/gitlab/sidekiq' diff --git a/spec/tasks/gitlab/snippets_rake_spec.rb b/spec/tasks/gitlab/snippets_rake_spec.rb index f21922e14b8..d40b784b3a0 100644 --- a/spec/tasks/gitlab/snippets_rake_spec.rb +++ b/spec/tasks/gitlab/snippets_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:snippets namespace rake task' do +RSpec.describe 'gitlab:snippets namespace rake task', :silence_stdout do let_it_be(:user) { create(:user)} let_it_be(:migrated) { create(:personal_snippet, :repository, author: user) } let(:non_migrated) { create_list(:personal_snippet, 3, author: user) } diff --git a/spec/tasks/gitlab/storage_rake_spec.rb b/spec/tasks/gitlab/storage_rake_spec.rb index abd44adbdcc..fefcd05af3b 100644 --- a/spec/tasks/gitlab/storage_rake_spec.rb +++ b/spec/tasks/gitlab/storage_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'rake gitlab:storage:*' do +RSpec.describe 'rake gitlab:storage:*', :silence_stdout do before do Rake.application.rake_require 'tasks/gitlab/storage' @@ -88,6 +88,27 @@ RSpec.describe 'rake gitlab:storage:*' do end end + shared_examples 'wait until database is ready' do + it 'checks if the database is ready once' do + expect(Gitlab::Database).to receive(:exists?).once + + run_rake_task(task) + end + + context 'handles custom env vars' do + before do + stub_env('MAX_DATABASE_CONNECTION_CHECKS' => 3) + stub_env('MAX_DATABASE_CONNECTION_INTERVAL' => 0.1) + end + + it 'tries for 3 times, polling every 0.1 seconds' do + expect(Gitlab::Database).to receive(:exists?).exactly(3).times.and_return(false) + + run_rake_task(task) + end + end + end + describe 'gitlab:storage:migrate_to_hashed' do let(:task) { 'gitlab:storage:migrate_to_hashed' } @@ -198,6 +219,10 @@ RSpec.describe 'rake gitlab:storage:*' do let(:task) { 'gitlab:storage:legacy_projects' } let(:create_collection) { create_list(:project, 3, :legacy_storage) } end + + it_behaves_like 'wait until database is ready' do + let(:task) { 'gitlab:storage:legacy_projects' } + end end describe 'gitlab:storage:list_legacy_projects' do @@ -227,6 +252,10 @@ RSpec.describe 'rake gitlab:storage:*' do let(:project) { create(:project, storage_version: 1) } let(:create_collection) { create_list(:upload, 3, model: project) } end + + it_behaves_like 'wait until database is ready' do + let(:task) { 'gitlab:storage:legacy_attachments' } + end end describe 'gitlab:storage:list_legacy_attachments' do diff --git a/spec/tasks/gitlab/terraform/migrate_rake_spec.rb b/spec/tasks/gitlab/terraform/migrate_rake_spec.rb index 4188521df8e..8d911010a2e 100644 --- a/spec/tasks/gitlab/terraform/migrate_rake_spec.rb +++ b/spec/tasks/gitlab/terraform/migrate_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:terraform_states' do +RSpec.describe 'gitlab:terraform_states', :silence_stdout do let_it_be(:version) { create(:terraform_state_version) } let(:logger) { instance_double(Logger) } @@ -13,7 +13,7 @@ RSpec.describe 'gitlab:terraform_states' do end before do - allow(Logger).to receive(:new).with(STDOUT).and_return(logger) + allow(Logger).to receive(:new).with($stdout).and_return(logger) end describe 'gitlab:terraform_states:migrate' do diff --git a/spec/tasks/gitlab/update_templates_rake_spec.rb b/spec/tasks/gitlab/update_templates_rake_spec.rb index 25151a2f3ae..7eccdf22a1f 100644 --- a/spec/tasks/gitlab/update_templates_rake_spec.rb +++ b/spec/tasks/gitlab/update_templates_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:update_project_templates rake task' do +RSpec.describe 'gitlab:update_project_templates rake task', :silence_stdout do let!(:tmpdir) { Dir.mktmpdir } before do diff --git a/spec/tasks/gitlab/uploads/check_rake_spec.rb b/spec/tasks/gitlab/uploads/check_rake_spec.rb index 4c6f16dbcf9..b3efe33c549 100644 --- a/spec/tasks/gitlab/uploads/check_rake_spec.rb +++ b/spec/tasks/gitlab/uploads/check_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:uploads rake tasks' do +RSpec.describe 'gitlab:uploads rake tasks', :silence_stdout do describe 'check' do let!(:upload) { create(:upload, path: Rails.root.join('spec/fixtures/banana_sample.gif')) } diff --git a/spec/tasks/gitlab/uploads/migrate_rake_spec.rb b/spec/tasks/gitlab/uploads/migrate_rake_spec.rb index 7f0f5c6767d..e293271ca67 100644 --- a/spec/tasks/gitlab/uploads/migrate_rake_spec.rb +++ b/spec/tasks/gitlab/uploads/migrate_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:uploads:migrate and migrate_to_local rake tasks' do +RSpec.describe 'gitlab:uploads:migrate and migrate_to_local rake tasks', :silence_stdout do let(:model_class) { nil } let(:uploader_class) { nil } let(:mounted_as) { nil } diff --git a/spec/tasks/gitlab/usage_data_rake_spec.rb b/spec/tasks/gitlab/usage_data_rake_spec.rb index 84269568b8b..acaf9b5729b 100644 --- a/spec/tasks/gitlab/usage_data_rake_spec.rb +++ b/spec/tasks/gitlab/usage_data_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:usage data take tasks' do +RSpec.describe 'gitlab:usage data take tasks', :silence_stdout do include UsageDataHelpers before do diff --git a/spec/tasks/gitlab/user_management_rake_spec.rb b/spec/tasks/gitlab/user_management_rake_spec.rb index 958055780d0..b13b004aaa4 100644 --- a/spec/tasks/gitlab/user_management_rake_spec.rb +++ b/spec/tasks/gitlab/user_management_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:user_management tasks' do +RSpec.describe 'gitlab:user_management tasks', :silence_stdout do before do Rake.application.rake_require 'tasks/gitlab/user_management' end diff --git a/spec/tasks/gitlab/web_hook_rake_spec.rb b/spec/tasks/gitlab/web_hook_rake_spec.rb index 9f373e3a20a..2c582dc78f8 100644 --- a/spec/tasks/gitlab/web_hook_rake_spec.rb +++ b/spec/tasks/gitlab/web_hook_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:web_hook namespace rake tasks' do +RSpec.describe 'gitlab:web_hook namespace rake tasks', :silence_stdout do let_it_be(:group, refind: true) { create(:group) } let_it_be(:project1, reload: true) { create(:project, namespace: group) } let_it_be(:project2, reload: true) { create(:project, namespace: group) } diff --git a/spec/tasks/gitlab/workhorse_rake_spec.rb b/spec/tasks/gitlab/workhorse_rake_spec.rb index 0757f6ca015..6b5985a2a8a 100644 --- a/spec/tasks/gitlab/workhorse_rake_spec.rb +++ b/spec/tasks/gitlab/workhorse_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:workhorse namespace rake task' do +RSpec.describe 'gitlab:workhorse namespace rake task', :silence_stdout do before :all do Rake.application.rake_require 'tasks/gitlab/workhorse' end diff --git a/spec/tasks/gitlab/x509/update_rake_spec.rb b/spec/tasks/gitlab/x509/update_rake_spec.rb index b166e73935a..dca4f07cda7 100644 --- a/spec/tasks/gitlab/x509/update_rake_spec.rb +++ b/spec/tasks/gitlab/x509/update_rake_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'gitlab:x509 namespace rake task' do +RSpec.describe 'gitlab:x509 namespace rake task', :silence_stdout do before :all do Rake.application.rake_require 'tasks/gitlab/x509/update' end diff --git a/spec/tasks/migrate/schema_check_rake_spec.rb b/spec/tasks/migrate/schema_check_rake_spec.rb index aebb3a6551f..1b60b63ad84 100644 --- a/spec/tasks/migrate/schema_check_rake_spec.rb +++ b/spec/tasks/migrate/schema_check_rake_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require 'rake' -RSpec.describe 'schema_version_check rake task' do +RSpec.describe 'schema_version_check rake task', :silence_stdout do include StubENV before :all do diff --git a/spec/tasks/tokens_spec.rb b/spec/tasks/tokens_spec.rb index 13fcd37b426..3f7271d4be1 100644 --- a/spec/tasks/tokens_spec.rb +++ b/spec/tasks/tokens_spec.rb @@ -2,7 +2,7 @@ require 'rake_helper' -RSpec.describe 'tokens rake tasks' do +RSpec.describe 'tokens rake tasks', :silence_stdout do let!(:user) { create(:user) } before do |