diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2016-03-14 17:18:52 +0300 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2016-03-14 17:55:45 +0300 |
commit | a02fe251df7ea7316f51850fe603e7e5ac4431e2 (patch) | |
tree | ea6f7078130c17d29e864914408e70497e2238ad /spec/services/projects | |
parent | 37ba5a12b515172b76d28e112ab9899823163717 (diff) |
Allow project housekeeping only once an hour
Diffstat (limited to 'spec/services/projects')
-rw-r--r-- | spec/services/projects/housekeeping_service_spec.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/services/projects/housekeeping_service_spec.rb b/spec/services/projects/housekeeping_service_spec.rb new file mode 100644 index 00000000000..7cddeb5c354 --- /dev/null +++ b/spec/services/projects/housekeeping_service_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe Projects::HousekeepingService do + subject { Projects::HousekeepingService.new(project) } + let(:project) { create :project } + + describe :execute do + before do + project.pushes_since_gc = 3 + project.save! + end + + it 'enqueues a sidekiq job' do + expect(subject).to receive(:try_obtain_lease).and_return(true) + expect(GitlabShellWorker).to receive(:perform_async).with(:gc, project.path_with_namespace) + + expect(subject.execute).to include('successfully started') + expect(project.pushes_since_gc).to eq(0) + end + + it 'does not enqueue a job when no lease can be obtained' do + expect(subject).to receive(:try_obtain_lease).and_return(false) + expect(GitlabShellWorker).not_to receive(:perform_async) + + expect(subject.execute).to include('already triggered') + expect(project.pushes_since_gc).to eq(3) + end + end + + describe :needed? do + it 'when the count is low enough' do + expect(subject.needed?).to eq(false) + end + + it 'when the count is high enough' do + allow(project).to receive(:pushes_since_gc).and_return(10) + expect(subject.needed?).to eq(true) + end + end +end
\ No newline at end of file |