diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2018-07-06 18:23:51 +0300 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2018-07-10 15:43:58 +0300 |
commit | db0f150516404c6e7951bc961eab45be11b5fcf5 (patch) | |
tree | 74792807be2e5b7d44740ee50ddcdd57e6e9c180 /spec | |
parent | 19966e7095fd6357183afb8e009c7f8e78a05591 (diff) |
Reschedule DeleteDiffFiles until there is none left to remove
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/background_migration/delete_diff_files_spec.rb | 25 |
1 files changed, 20 insertions, 5 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 f128c9ecf1b..247e0786dd6 100644 --- a/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb +++ b/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb @@ -65,10 +65,27 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, schema: 20180 .not_to change { merge_request_diff.merge_request_diff_files.count } .from(20) end + + it 'reschedules itself when should_wait_deadtuple_vacuum' do + Sidekiq::Testing.fake! do + worker = described_class.new + + allow(worker).to receive(:should_wait_deadtuple_vacuum?) { true } + + expect(BackgroundMigrationWorker) + .to receive(:perform_in) + .with(described_class::VACUUM_WAIT_TIME, 'DeleteDiffFiles') + .and_call_original + + worker.perform + + expect(BackgroundMigrationWorker.jobs.size).to eq(1) + end + end end - describe '#wait_deadtuple_vacuum' do - it 'sleeps process for VACUUM_WAIT_TIME when hitting DEAD_TUPLES_THRESHOLD', :postgresql do + describe '#should_wait_deadtuple_vacuum?' do + it 'returns true when hitting merge_request_diff_files hits 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' }] @@ -78,9 +95,7 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, schema: 20180 .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) + expect(worker.should_wait_deadtuple_vacuum?).to be(true) end end end |