summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2018-07-06 18:19:10 +0000
committerRobert Speicher <robert@gitlab.com>2018-07-06 18:19:10 +0000
commitfbaaa5743149395cacd02f7651971347bb404a43 (patch)
tree2ac82b8ca9cb8025f308c98480fb049aae84fef0 /spec
parent23f03215409a81be35f02511660c34832738da9f (diff)
parentb33661d6ec8498ae1dadfb3b2be0e4a80e61f108 (diff)
downloadgitlab-ce-fbaaa5743149395cacd02f7651971347bb404a43.tar.gz
Merge branch 'sh-guard-repository-checks' into 'master'
Add ExclusiveLease guards for RepositoryCheck::{DispatchWorker,BatchWorker} See merge request gitlab-org/gitlab-ce!20441
Diffstat (limited to 'spec')
-rw-r--r--spec/workers/repository_check/batch_worker_spec.rb8
-rw-r--r--spec/workers/repository_check/dispatch_worker_spec.rb8
2 files changed, 16 insertions, 0 deletions
diff --git a/spec/workers/repository_check/batch_worker_spec.rb b/spec/workers/repository_check/batch_worker_spec.rb
index 6bc551be9ad..ede271b2cdd 100644
--- a/spec/workers/repository_check/batch_worker_spec.rb
+++ b/spec/workers/repository_check/batch_worker_spec.rb
@@ -62,4 +62,12 @@ describe RepositoryCheck::BatchWorker do
expect(subject.perform(shard_name)).to eq([])
end
+
+ it 'does not run if the exclusive lease is taken' do
+ allow(subject).to receive(:try_obtain_lease).and_return(false)
+
+ expect(subject).not_to receive(:perform_repository_checks)
+
+ subject.perform(shard_name)
+ end
end
diff --git a/spec/workers/repository_check/dispatch_worker_spec.rb b/spec/workers/repository_check/dispatch_worker_spec.rb
index 20a4f1f5344..7877429aa8f 100644
--- a/spec/workers/repository_check/dispatch_worker_spec.rb
+++ b/spec/workers/repository_check/dispatch_worker_spec.rb
@@ -11,6 +11,14 @@ describe RepositoryCheck::DispatchWorker do
subject.perform
end
+ it 'does nothing if the exclusive lease is taken' do
+ allow(subject).to receive(:try_obtain_lease).and_return(false)
+
+ expect(RepositoryCheck::BatchWorker).not_to receive(:perform_async)
+
+ subject.perform
+ end
+
it 'dispatches work to RepositoryCheck::BatchWorker' do
expect(RepositoryCheck::BatchWorker).to receive(:perform_async).at_least(:once)