diff options
Diffstat (limited to 'spec')
3 files changed, 26 insertions, 82 deletions
diff --git a/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb b/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb index d8497315e2d..f128c9ecf1b 100644 --- a/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb +++ b/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb @@ -4,19 +4,19 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, schema: 20180 describe '#perform' do context 'when diff files can be deleted' do let(:merge_request) { create(:merge_request, :merged) } - let(:merge_request_diff) do + let!(:merge_request_diff) do merge_request.create_merge_request_diff merge_request.merge_request_diffs.first end it 'deletes all merge request diff files' do - expect { described_class.new.perform(merge_request_diff.id) } + expect { described_class.new.perform } .to change { merge_request_diff.merge_request_diff_files.count } .from(20).to(0) end it 'updates state to without_files' do - expect { described_class.new.perform(merge_request_diff.id) } + expect { described_class.new.perform } .to change { merge_request_diff.reload.state } .from('collected').to('without_files') end @@ -25,7 +25,7 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, schema: 20180 expect(described_class::MergeRequestDiffFile).to receive_message_chain(:where, :delete_all) .and_raise - expect { described_class.new.perform(merge_request_diff.id) } + expect { described_class.new.perform } .to raise_error merge_request_diff.reload @@ -40,7 +40,7 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, schema: 20180 merge_request.create_merge_request_diff merge_request_diff = merge_request.merge_request_diffs.first - expect { described_class.new.perform(merge_request_diff.id) } + expect { described_class.new.perform } .not_to change { merge_request_diff.merge_request_diff_files.count } .from(20) end @@ -52,7 +52,7 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, schema: 20180 merge_request_diff.clean! - expect { described_class.new.perform(merge_request_diff.id) } + expect { described_class.new.perform } .not_to change { merge_request_diff.merge_request_diff_files.count } .from(20) end @@ -61,9 +61,26 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, schema: 20180 merge_request = create(:merge_request, :merged) merge_request_diff = merge_request.merge_request_diff - expect { described_class.new.perform(merge_request_diff.id) } + expect { described_class.new.perform } .not_to change { merge_request_diff.merge_request_diff_files.count } .from(20) end end + + describe '#wait_deadtuple_vacuum' do + it 'sleeps process for VACUUM_WAIT_TIME when hitting DEAD_TUPLES_THRESHOLD', :postgresql do + worker = described_class.new + threshold_query_result = [{ "n_dead_tup" => described_class::DEAD_TUPLES_THRESHOLD.to_s }] + normal_query_result = [{ "n_dead_tup" => '3' }] + + allow(worker) + .to receive(:execute_statement) + .with(/SELECT n_dead_tup */) + .and_return(threshold_query_result, normal_query_result) + + expect(worker).to receive(:sleep).with(described_class::VACUUM_WAIT_TIME).once + + worker.wait_deadtuple_vacuum(1) + end + end end diff --git a/spec/lib/gitlab/background_migration/schedule_diff_files_deletion_spec.rb b/spec/lib/gitlab/background_migration/schedule_diff_files_deletion_spec.rb deleted file mode 100644 index 04f20b75531..00000000000 --- a/spec/lib/gitlab/background_migration/schedule_diff_files_deletion_spec.rb +++ /dev/null @@ -1,73 +0,0 @@ -require 'spec_helper' - -describe Gitlab::BackgroundMigration::ScheduleDiffFilesDeletion, :migration, schema: 20180619121030 do - describe '#perform' do - let(:merge_request_diffs) { table(:merge_request_diffs) } - let(:diff_files) { table(:merge_request_diff_files) } - let(:merge_requests) { table(:merge_requests) } - let(:namespaces) { table(:namespaces) } - let(:projects) { table(:projects) } - - def diff_file_params(extra_params = {}) - extra_params.merge(new_file: false, - renamed_file: false, - too_large: false, - deleted_file: false, - a_mode: 'foo', - b_mode: 'bar', - new_path: 'xpto', - old_path: 'kux', - diff: 'content') - end - - def create_diffs(id:, files_number:, state: 'collected') - merge_request_diffs.create!(id: id, merge_request_id: 1, state: state) - files_number.times.to_a.each do |index| - params = diff_file_params(merge_request_diff_id: id, relative_order: index) - - diff_files.create!(params) - end - end - - before do - stub_const("#{described_class.name}::DELETION_BATCH", 10) - - namespaces.create!(id: 1, name: 'gitlab', path: 'gitlab') - projects.create!(id: 1, namespace_id: 1, name: 'gitlab', path: 'gitlab') - - merge_requests.create!(id: 1, target_project_id: 1, source_project_id: 1, target_branch: 'feature', source_branch: 'master', state: 'merged') - end - - it 'correctly schedules diff file deletion workers' do - Sidekiq::Testing.fake! do - Timecop.freeze do - create_diffs(id: 1, files_number: 25) - create_diffs(id: 2, files_number: 11) - create_diffs(id: 3, files_number: 4, state: 'without_files') - create_diffs(id: 4, files_number: 5, state: 'empty') - create_diffs(id: 5, files_number: 9) - - worker = described_class.new - - expect(worker).to receive(:log_days_to_process_all_jobs).with(1.second + 2.5.minutes + 1.1.minutes + 0.9.minutes) - - worker.perform - - expect(described_class::MIGRATION).to be_scheduled_delayed_migration(1.second, 1) - expect(described_class::MIGRATION).to be_scheduled_delayed_migration(1.second + 2.5.minutes, 2) - expect(described_class::MIGRATION).to be_scheduled_delayed_migration(1.second + 2.5.minutes + 1.1.minutes, 5) - expect(BackgroundMigrationWorker.jobs.size).to eq(3) - end - end - end - end - - describe '#days_to_process_all_jobs' do - it 'logs how many days it will take to run all jobs' do - expect(Rails).to receive_message_chain(:logger, :info) - .with("Gitlab::BackgroundMigration::DeleteDiffFiles will take 3 days to be processed") - - described_class.new.log_days_to_process_all_jobs(3.days.seconds) - end - end -end diff --git a/spec/migrations/enqueue_delete_diff_files_workers_spec.rb b/spec/migrations/enqueue_delete_diff_files_workers_spec.rb index 3d19c6fcc10..803830d81cf 100644 --- a/spec/migrations/enqueue_delete_diff_files_workers_spec.rb +++ b/spec/migrations/enqueue_delete_diff_files_workers_spec.rb @@ -2,11 +2,11 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20180619121030_enqueue_delete_diff_files_workers.rb') describe EnqueueDeleteDiffFilesWorkers, :migration, :sidekiq do - it 'correctly schedules diff file deletion scheduler' do + it 'correctly schedules diff files deletion' do Sidekiq::Testing.fake! do expect(BackgroundMigrationWorker) .to receive(:perform_async) - .with(described_class::SCHEDULER) + .with(described_class::MIGRATION) .and_call_original migrate! |