Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-10-25 17:01:24 +0300
committerYorick Peterse <yorickpeterse@gmail.com>2016-10-25 17:02:36 +0300
commit3b4af59a5fed342bf7a4718dba6189cdf1d0c017 (patch)
tree01334aa305fe43e442a4ec8d583d55ed02501ca0 /spec/workers/project_cache_worker_spec.rb
parent9a6770388c0e93f98952a40cc88bb7f5ecd23631 (diff)
Don't schedule ProjectCacheWorker unless needed
This changes ProjectCacheWorker.perform_async so it only schedules a job when no lease for the given project is present. This ensures we don't end up scheduling hundreds of jobs when they won't be executed anyway.
Diffstat (limited to 'spec/workers/project_cache_worker_spec.rb')
-rw-r--r--spec/workers/project_cache_worker_spec.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/spec/workers/project_cache_worker_spec.rb b/spec/workers/project_cache_worker_spec.rb
index f5b60b90d11..bfa8c0ff2c6 100644
--- a/spec/workers/project_cache_worker_spec.rb
+++ b/spec/workers/project_cache_worker_spec.rb
@@ -5,6 +5,26 @@ describe ProjectCacheWorker do
subject { described_class.new }
+ describe '.perform_async' do
+ it 'schedules the job when no lease exists' do
+ allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:exists?).
+ and_return(false)
+
+ expect_any_instance_of(described_class).to receive(:perform)
+
+ described_class.perform_async(project.id)
+ end
+
+ it 'does not schedule the job when a lease exists' do
+ allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:exists?).
+ and_return(true)
+
+ expect_any_instance_of(described_class).not_to receive(:perform)
+
+ described_class.perform_async(project.id)
+ end
+ end
+
describe '#perform' do
context 'when an exclusive lease can be obtained' do
before do