diff options
Diffstat (limited to 'spec/tasks/gitlab')
-rw-r--r-- | spec/tasks/gitlab/backup_rake_spec.rb | 34 | ||||
-rw-r--r-- | spec/tasks/gitlab/db_rake_spec.rb | 74 |
2 files changed, 80 insertions, 28 deletions
diff --git a/spec/tasks/gitlab/backup_rake_spec.rb b/spec/tasks/gitlab/backup_rake_spec.rb index a2cc2b12e5e..212a7f74b40 100644 --- a/spec/tasks/gitlab/backup_rake_spec.rb +++ b/spec/tasks/gitlab/backup_rake_spec.rb @@ -325,11 +325,13 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do end let!(:project_a) { create(:project, :repository) } + let!(:project_a_wiki_page) { create(:wiki_page, container: project_a) } + let!(:project_a_design) { create(:design, :with_file, issue: create(:issue, project: project_a)) } let!(:project_b) { create(:project, :repository, repository_storage: 'test_second_storage') } let!(:b_storage_dir) { File.join(test_second_storage_dir, File.dirname(project_b.disk_path)) } - context 'no concurrency' do - it 'includes repositories in all repository storages' do + shared_examples 'includes repositories in all repository storages' do + specify :aggregate_failures do expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout tar_contents, exit_status = Gitlab::Popen.popen( @@ -337,27 +339,25 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do ) expect(exit_status).to eq(0) - expect(tar_contents).to match("repositories/#{project_a.disk_path}.bundle") - expect(tar_contents).to match("repositories/#{project_b.disk_path}.bundle") + expect(tar_contents).to include( + "repositories/#{project_a.disk_path}.bundle", + "repositories/#{project_a.disk_path}.wiki.bundle", + "repositories/#{project_a.disk_path}.design.bundle", + "repositories/#{project_b.disk_path}.bundle" + ) end end + context 'no concurrency' do + it_behaves_like 'includes repositories in all repository storages' + end + context 'with concurrency' do before do stub_env('GITLAB_BACKUP_MAX_CONCURRENCY', 4) end - it 'includes repositories in all repository storages' do - expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout - - tar_contents, exit_status = Gitlab::Popen.popen( - %W{tar -tvf #{backup_tar} repositories} - ) - - expect(exit_status).to eq(0) - expect(tar_contents).to match("repositories/#{project_a.disk_path}.bundle") - expect(tar_contents).to match("repositories/#{project_b.disk_path}.bundle") - end + it_behaves_like 'includes repositories in all repository storages' end end @@ -370,7 +370,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do end it 'has defaults' do - expect_next_instance_of(::Backup::Repository) do |instance| + expect_next_instance_of(::Backup::Repositories) do |instance| expect(instance).to receive(:dump) .with(max_concurrency: 1, max_storage_concurrency: 1) .and_call_original @@ -383,7 +383,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do stub_env('GITLAB_BACKUP_MAX_CONCURRENCY', 5) stub_env('GITLAB_BACKUP_MAX_STORAGE_CONCURRENCY', 2) - expect_next_instance_of(::Backup::Repository) do |instance| + expect_next_instance_of(::Backup::Repositories) do |instance| expect(instance).to receive(:dump) .with(max_concurrency: 5, max_storage_concurrency: 2) .and_call_original diff --git a/spec/tasks/gitlab/db_rake_spec.rb b/spec/tasks/gitlab/db_rake_spec.rb index 99efd394e83..e4630aefb85 100644 --- a/spec/tasks/gitlab/db_rake_spec.rb +++ b/spec/tasks/gitlab/db_rake_spec.rb @@ -164,25 +164,77 @@ RSpec.describe 'gitlab:db namespace rake task' do end end + describe 'drop_tables' do + subject { run_rake_task('gitlab:db:drop_tables') } + + let(:tables) { %w(one two) } + let(:views) { %w(three four) } + let(:connection) { ActiveRecord::Base.connection } + + before do + allow(connection).to receive(:execute).and_return(nil) + + allow(connection).to receive(:tables).and_return(tables) + allow(connection).to receive(:views).and_return(views) + end + + it 'drops all tables, except schema_migrations' do + expect(connection).to receive(:execute).with('DROP TABLE IF EXISTS "one" CASCADE') + expect(connection).to receive(:execute).with('DROP TABLE IF EXISTS "two" CASCADE') + + subject + end + + it 'drops all views' do + expect(connection).to receive(:execute).with('DROP VIEW IF EXISTS "three" CASCADE') + expect(connection).to receive(:execute).with('DROP VIEW IF EXISTS "four" CASCADE') + + subject + end + + it 'truncates schema_migrations table' do + expect(connection).to receive(:execute).with('TRUNCATE schema_migrations') + + subject + end + + it 'drops extra schemas' do + Gitlab::Database::EXTRA_SCHEMAS.each do |schema| + expect(connection).to receive(:execute).with("DROP SCHEMA IF EXISTS \"#{schema}\"") + end + + subject + end + end + describe 'reindex' do + let(:reindex) { double('reindex') } + let(:indexes) { double('indexes') } + context 'when no index_name is given' do - it 'raises an error' do - expect do - run_rake_task('gitlab:db:reindex', '') - end.to raise_error(ArgumentError, /must give the index name/) + it 'rebuilds a random number of large indexes' do + expect(Gitlab::Database::Reindexing).to receive_message_chain('candidate_indexes.random_few').and_return(indexes) + expect(Gitlab::Database::Reindexing).to receive(:perform).with(indexes) + + run_rake_task('gitlab:db:reindex') end end - it 'calls the index rebuilder with the proper arguments' do - reindex = double('rebuilder') + context 'with index name given' do + let(:index) { double('index') } - expect(Gitlab::Database::ConcurrentReindex).to receive(:new) - .with('some_index_name', logger: instance_of(Logger)) - .and_return(reindex) + it 'calls the index rebuilder with the proper arguments' do + expect(Gitlab::Database::PostgresIndex).to receive(:by_identifier).with('public.foo_idx').and_return(index) + expect(Gitlab::Database::Reindexing).to receive(:perform).with(index) - expect(reindex).to receive(:execute) + run_rake_task('gitlab:db:reindex', '[public.foo_idx]') + end + + it 'raises an error if the index does not exist' do + expect(Gitlab::Database::PostgresIndex).to receive(:by_identifier).with('public.absent_index').and_raise(ActiveRecord::RecordNotFound) - run_rake_task('gitlab:db:reindex', '[some_index_name]') + expect { run_rake_task('gitlab:db:reindex', '[public.absent_index]') }.to raise_error(ActiveRecord::RecordNotFound) + end end end |